Open
Description
Bug Report
When defining a function expecting a generic class and a generic value — tied to the same TypeVar
—, mypy is not able to infer the type of the argument if the generic type is a TypedDict
.
It works well for scalar types, if the variable is explicitly defined as the typed dict type, or even more surprising, if the first generic argument is binded via a functools.partial
.
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&gist=a6d36519fbd58e5c9b77999eedd16132
import typing
import functools
T = typing.TypeVar("T")
class A(typing.Generic[T]): ...
def f(a: A[T], t: T) -> None: ...
class D(typing.TypedDict):
x: int
a_typed_dict = A[D]()
f(a_typed_dict, {"x": 1}) # error: Cannot infer type argument 1 of "f" [misc]
Expected Behavior
The t
argument is correctly validated as a D
typed dict.
Actual Behavior
The following error message is returned:
error: Cannot infer type argument 1 of "f" [misc]
Your Environment
- Mypy version used: 1.15
- Python version used: 3.12