False-positive S5655 passing bool as float

Then tell us:

  • What language is this for? Python
  • Which rule? S5655
  • Why do you believe it’s a false-positive/false-negative?
    • Because a bool is an int, and int passes. Also, mypy and pyright.
  • SonarLint 4.2.2
# func expects a float
def fun(f: float) -> None:
    print(1.0 + f)

# passing an int works
fun(1)

# passing a bool also works, but yields S5655
fun(True)

# but True is an int and thus should pass!
print(isinstance(True, int))

Hello @bers,

Thank you for bringing this issue up. Indeed, we should take into account that a boolean is easily converted to a float, and therefore we shouldn’t be raising an issue here. I have created a ticket to fix this.

Best,
Jérémi

1 Like