mypy
c2779243 - Implement Unpack of TypeVars for **kwargs inference

Commit
144 days ago
Implement Unpack of TypeVars for **kwargs inference Allow `**kwargs: Unpack[K]` where K is a TypeVar bound to TypedDict. This enables inferring TypedDict types from keyword arguments at call sites. Example: def f[K: BaseTypedDict](**kwargs: Unpack[K]) -> K: ... result = f(x=1, y="hello") # K inferred as TypedDict({'x': int, 'y': str}) Changes: - semanal.py: Accept TypeVar with TypedDict bound in remove_unpack_kwargs(), keep UnpackType for constraint inference - semanal_typeargs.py: Allow TypeVar with TypedDict bound in visit_unpack_type() - constraints.py: Generate TypedDict constraints from actual kwargs - types.py: Handle TypeVar in with_unpacked_kwargs() - checkexpr.py: Re-expand kwargs after TypeVar inference Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Author
Committer
Parents
Loading