-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
The following code fails to typecheck:
from typing import Any, Type, TypeVar
from mypy_extensions import TypedDict
_T = TypeVar('_T')
class C(TypedDict):
x: str
class D:
x: str
def gen_row() -> Any:
return {'x': 1}
def foo(cls: Type[_T]) -> _T:
return gen_row()
def print_c(c: C):
print(c)
def print_d(d: D):
print(d)
print_c(foo(C))
print_d(foo(D))
reveal_type(foo(C))
reveal_type(foo(D))
producing the following error:
$ mypy test.py
test.py:24: error: Argument 1 to "print_c" has incompatible type "test.C"; expected "C"
test.py:26: error: Revealed type is 'test.C*'
test.py:27: error: Revealed type is 'test.D*'
I think this is a bug related to TypedDict
, as using any other class (like D
in the sample code) works just fine.
Note also that one cannot tighten T
with a bound=TypedDict
, as that produces the error:
Invalid type "mypy_extensions.TypedDict"
.
- What are the versions of mypy and Python you are using?
$ mypy --version
mypy 0.620
$ python --version
Python 3.6.5
- What are the mypy flags you are using? (For example --strict-optional)
mypy.ini
is:
[mypy]
ignore_missing_imports = True
strict_optional = True
warn_unused_ignores = True
warn_redundant_casts = True
warn_unused_configs = True
check_untyped_defs = True