Closed
Description
Bool is a subtype of int.
The goals of this issue is to document this in a good way in the mypy documentation.
A short example:
This can cause problems when a function is expected to return an int, but in reality returns a bool.
Take this code for example:
def example(x: int) -> int:
if x := x > 0:
return x
return 0
The expectation is that this function will return only positive integers or 0.
What happens is that it will return bool
for positive integers and 0
for non positive ints.
This is a weird edge case for python3. See also this blog:
https://medium.com/@timb07/python-bool-wat-ab0e28d879c7
As per: #8053