-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
int
inconsistently considered a subtype of float
#17223
Labels
bug
mypy got something wrong
Comments
Another way to put it (playground): from typing import Literal
a: int = 3
if isinstance(a, float):
reveal_type(a) # Never touched at runtime, but Mypy says `int`.
b: Literal[3] = 3
if isinstance(b, float):
reveal_type(b) # Never touched at runtime, correctly reported as unreachable. |
Closing as a duplicate of #11516 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From PEP 484:
So mypy considers this legal (mypy 1.10.0, with
--strict
):But when checking objects with
isinstance
, it thinks a variable annotated withfloat
cannot be anint
:I think this is a bug, since
float
is always implicitlyfloat | int
. I'd expect mypy to not flag this as unreachable and reveal the type ofx
asint
. (that's the behaviourpyright
currently has)Here's another potentially buggy example:
If you call this function as
f(42)
, which mypy allows, the second branch will be selected at runtime.The text was updated successfully, but these errors were encountered: