Bug Report
All attributes of TypedDict are "object", not the annotated type when using TypeVar
To Reproduce
class A(TypedDict):
x: int
y: str
class B(A):
z: Dict[str, str]
T = TypeVar('T', bound=A)
def my_func(things: List[T]):
for t in things:
x_val: int = t['x'] # Incompatible types in assignment (expression has type "object", variable has type "int")
y_val: str = t['y'] # Incompatible types in assignment (expression has type "object", variable has type "str")
my_things: List[B] = [
{'x': 1, 'y': '2', 'z': {'foo': 'bar'}},
{'x': 1, 'y': '2', 'z': {'foo': 'baz'}},
]
my_func(my_things)
Can do the same but with my_things: List[A] passed into the same function.
Doing something like z_val: Dict[str, str] = my_b_type['z'].get('foo') raises an error: "object" has no attribute "get"
Expected Behavior
It respects the type annotations and has access to attributes/methods of the type.
Actual Behavior
error: Incompatible types in assignment (expression has type "object", variable has type "int")
error: Incompatible types in assignment (expression has type "object", variable has type "str")
error: "object" has no attribute "get"
Your Environment
- Mypy version used: 0.812
- Mypy configuration options from
mypy.ini (and other config files): n/a
- Python version used: 3.8.13
Bug Report
All attributes of TypedDict are "object", not the annotated type when using TypeVar
To Reproduce
Can do the same but with
my_things: List[A]passed into the same function.Doing something like
z_val: Dict[str, str] = my_b_type['z'].get('foo')raises anerror: "object" has no attribute "get"Expected Behavior
It respects the type annotations and has access to attributes/methods of the type.
Actual Behavior
Your Environment
mypy.ini(and other config files): n/a