-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder
Description
Bug Report
issubclass appears to not narrow down possible types.
To Reproduce
from typing import Any, Mapping, MutableMapping
def test_mutablemapping(obj: Mapping[Any, Any]) -> MutableMapping[Any, Any]:
if issubclass(type(obj), MutableMapping):
return obj # error: Incompatible types in assignment (expression has type "Mapping[Any, Any]", variable has type "MutableMapping[Any, Any]")
else:
return dict(obj)Expected Behavior
To narrow down in similar fashion to isinstance:
from typing import Any, Mapping, MutableMapping
def test_mutablemapping2(obj: Mapping[Any, Any]) -> MutableMapping[Any, Any]:
if isinstance(obj, MutableMapping):
return obj
else:
return dict(obj)Your Environment
- Mypy version used: 0.910
- Mypy command-line flags: default
- Mypy configuration options from
mypy.ini(and other config files): default - Python version used: 3.8.8
- Operating system and version: Windows 10
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder