You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Are you reporting a bug, or opening a feature request? Bug
Please insert below the code you are checking with mypy.
Sample 1 (mypy_error.py):
from numbers import Number
def is_very_large(x: Number):
return x > 9000
Sample 2 (mypy_error2.py):
from numbers import Number
def is_foo(data: dict):
x = data["x"]
if isinstance(x, Number) and x < 9000:
return True
else:
return False
Note: Running mypy on Sample 2 succeeds if the dict annotation is removed from data or if the first two lines of the function are replaced with def is_foo(x):.
What is the actual behavior/output?
mypy_error2.py:5: error: Unsupported operand types for > ("int" and "Number")
mypy_error.py:4: error: Unsupported operand types for < ("int" and "Number")
Found 2 errors in 2 files (checked 2 source files)
Note that the comparison operators shown in the error messages are the opposite of what appears in the code!
What is the behavior/output you expect? No errors, as int and Number should be fully comparable
What are the versions of mypy and Python you are using? mypy 0.770, Python 3.7.6
Do you see the same issue after installing mypy from Git master? Yes (commit 11c6888)
What are the mypy flags you are using? None
The text was updated successfully, but these errors were encountered:
This is false, int and Number are not fully comparable:
λ cat test51.py
from numbers import Number
def is_very_large(x: Number) -> None:
assert isinstance(x, Number)
return x > 9000
is_very_large(complex(1, -1))
λ python3 test51.py
Traceback (most recent call last):
File "test51.py", line 7, in <module>
is_very_large(complex(1, -1))
File "test51.py", line 5, in is_very_large
return x > 9000
TypeError: '>' not supported between instances of 'complex' and 'int'
Sample 1 (
mypy_error.py
):Sample 2 (
mypy_error2.py
):Note: Running
mypy
on Sample 2 succeeds if thedict
annotation is removed fromdata
or if the first two lines of the function are replaced withdef is_foo(x):
.Note that the comparison operators shown in the error messages are the opposite of what appears in the code!
Do you see the same issue after installing mypy from Git master? Yes (commit 11c6888)
The text was updated successfully, but these errors were encountered: