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
Type is not narrowed in else clause following check via type()
To Reproduce
defcheck_type(a: int|str) ->None:
iftype(a) isint:
my_int: int=aelse:
my_str: str=a# error: Incompatible types in assignment (expression has type "int | str", variable has type "str") [assignment]
Thank you. I guess that is why isinstance should be the preferred way to perform type narrowing. When I used custom classes with the @final decorator then the type is properly narrowed via type() as expected.
Bug Report
Type is not narrowed in else clause following check via type()
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.13&gist=20dd8e7b2f2f3a3795a78360b3627be7
Expected Behavior
Success: no issues found in 1 source file
Actual Behavior
error: Incompatible types in assignment (expression has type "int | str", variable has type "str") [assignment]
Your Environment
The text was updated successfully, but these errors were encountered: