1

The example below returns a boolean instead of a float. This passes mypy and shows no errors in the PyCharm editor.

def add(a: float, b: float) -> float:
    return False

You can test this using the online mypy checker https://mypy-play.net/?mypy=latest&python=3.9&gist=92430212fc6c5e31b91f12154ef11998

How do I get mypy to complain here?

Neil
  • 8,925
  • 10
  • 44
  • 49
  • Also see [Why bool and int are not considered as a type error when str and float is required?](https://stackoverflow.com/q/56099712/7851470) – Georgy Nov 22 '20 at 19:00
  • Thanks, I can see that booleans are integers `isinstance(False, int) == True`. The duplicate question linked doesn't answer my question. Perhaps you can link your question as that does. – Neil Nov 22 '20 at 19:24
  • Unfortunately, I don't have a gold badge in Python or mypy tag to do that. But we could ping @jonrsharpe and ask him to edit the duplicate target. – Georgy Nov 22 '20 at 20:14
  • Added; thanks @Georgy – jonrsharpe Nov 22 '20 at 20:19

0 Answers0