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
when an argument is annotated as having type float, an argument of type int is acceptable
So mypy considers this legal (mypy 1.10.0, with --strict):
deff(x: float) ->None:
passf(42)
But when checking objects with isinstance, it thinks a variable annotated with float cannot be an int:
deff(x: float) ->None:
ifnotisinstance(x, float):
print("💀") # error: Statement is unreachable [unreachable]reveal_type(x) # no diagnosticsf(42)
I think this is a bug, since float is always implicitly float | int. I'd expect mypy to not flag this as unreachable and reveal the type of x as int. (that's the behaviour pyright currently has)
Here's another potentially buggy example:
deff(x: float|str) ->None:
ifisinstance(x, float):
reveal_type(x) # Revealed type is "builtins.float"else:
reveal_type(x) # Revealed type is "builtins.str"
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:
fromtypingimportLiterala: int=3ifisinstance(a, float):
reveal_type(a) # Never touched at runtime, but Mypy says `int`.b: Literal[3] =3ifisinstance(b, float):
reveal_type(b) # Never touched at runtime, correctly reported as unreachable.
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: