Bug Report
To Reproduce
fromtypingimportAny, Generic, TypeVarT=TypeVar("T")
classFoo(Generic[T]):
def__init__(self, value: T):
self.value=valuedefidentity(value: T) ->Foo[T]:
ifisinstance(value, str):
returnFoo(value)
returnFoo(value)Expected Behavior
mypy should be able to tell that in the type-guarded block, T == str and use that to qualify the types.
Actual Behavior
mypy reports an error Argument 1 to "Foo" has incompatible type "str"; expected "T" in the type-guarded block in identity().
Your Environment
- Mypy version used: 0.910
- Mypy command-line flags: N/A
- Mypy configuration options from
mypy.ini (and other config files): N/A - Python version used: 3.9
- Operating system and version: Windows 10
Bug Report
To Reproduce
Expected Behavior
mypy should be able to tell that in the type-guarded block,
T == strand use that to qualify the types.Actual Behavior
mypy reports an error
Argument 1 to "Foo" has incompatible type "str"; expected "T"in the type-guarded block inidentity().Your Environment
mypy.ini(and other config files): N/A