Closed
Description
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
from types import NoneType
def f(x: str | None):
if isinstance(x, NoneType):
reveal_type(x) # N: Revealed type is "None"
elif isinstance(x, str):
reveal_type(x) # N: Revealed type is "builtins.str"
reveal_type(x) # N: Revealed type is "Union[builtins.str, None]"
Actual Behavior
from types import NoneType
def f(x: str | None):
if isinstance(x, NoneType):
reveal_type(x)
elif isinstance(x, str):
reveal_type(x) # N: Revealed type is "builtins.str"
reveal_type(x) # N: Revealed type is "Union[builtins.str, None]"
Your Environment
- Mypy version used: Any version that implements PR Treating NoneType as None and warning against using NoneType. #13153
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini
(and other config files): None - Python version used: 3.10
- Operating system and version: Linux 5.15.0-41-generic 20.04.1-Ubuntu x86_64