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
isinstance check of mypy doesn't detect instances of NoneType (actual None), doesn't visit/check branches checked of isinstance() conditions.
Expected Behavior
fromtypesimportNoneTypedeff(x: str|None):
ifisinstance(x, NoneType):
reveal_type(x) # N: Revealed type is "None"elifisinstance(x, str):
reveal_type(x) # N: Revealed type is "builtins.str"reveal_type(x) # N: Revealed type is "Union[builtins.str, None]"
Actual Behavior
fromtypesimportNoneTypedeff(x: str|None):
ifisinstance(x, NoneType):
reveal_type(x)
elifisinstance(x, str):
reveal_type(x) # N: Revealed type is "builtins.str"reveal_type(x) # N: Revealed type is "Union[builtins.str, None]"
This is a pretty atypical way to check for None. The more idiomatic (and easier-to-read) approach takes advantage of the fact that None is a singleton and cannot be subclassed.
Bug Report
isinstance check of mypy doesn't detect instances of NoneType (actual None), doesn't visit/check branches checked of
isinstance()
conditions.Expected Behavior
Actual Behavior
Your Environment
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: