You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support Unpack with dict for keyword arguments: **kwargs: Unpack[dict[Literal["test"], ...]] #17241
Mypy has support for declaring kwargs as **kwargs: Unpack[SomeTypedDict].
However, sometimes for dicts with uniform value types, it's more convenient to declare them in terms of dict[Literal["key", "another"], ...]. Other times it's a pragmatic work-around to the lack of support for @final declaration for TypedDict (#7981).
changed the title [-]Support `Unpack` with `dict` for function arguments: `**kwargs: Unpack[dict[Literal["test"], ...]]`[/-][+]Support `Unpack` with `dict` for keyword arguments: `**kwargs: Unpack[dict[Literal["test"], ...]]`[/+]on May 14, 2024
What you're proposing here is not allowed by the typing spec currently. If you want to see something like this, you would need to extend the typing spec, probably through a new PEP as @AlexWaygood suggests. If you're interested in pursuing this, I recommend starting a discussion in the Python typing forum to see if you can gain support and consensus for such an idea.
Activity
intgr commentedon May 14, 2024
FWIW, Pyright also rejects this: https://pyright-play.net/?pyrightVersion=1.1.353&pythonVersion=3.12&pythonPlatform=Linux&strict=true&locale=en&code=GYJw9gtgBALgngBwJYDsDmUkQWEMoAySMApiAIYA2ANFAKooLkDGA1gFDsAmJwUJAD3LZKJABQAqCawDu5EGgDOALnqMWrANpckzGJqKkKlTQCJSimKYC6tVDGvWAlMvZR3UJosWdBwhKJiFjAAvACMAEwAzE7sQA
intgr commentedon May 14, 2024
Also when implementing this, it might be useful to allow
Mapping/MutableMappingin these contexts as well:[-]Support `Unpack` with `dict` for function arguments: `**kwargs: Unpack[dict[Literal["test"], ...]]`[/-][+]Support `Unpack` with `dict` for keyword arguments: `**kwargs: Unpack[dict[Literal["test"], ...]]`[/+]AlexWaygood commentedon May 14, 2024
I think you'd probably need to write a PEP if you want to expand the use of Unpack in this way
erictraut commentedon May 14, 2024
What you're proposing here is not allowed by the typing spec currently. If you want to see something like this, you would need to extend the typing spec, probably through a new PEP as @AlexWaygood suggests. If you're interested in pursuing this, I recommend starting a discussion in the Python typing forum to see if you can gain support and consensus for such an idea.
intgr commentedon May 15, 2024
Posted to typing forum: https://discuss.python.org/t/proposal-support-unpack-dict-for-typing-keyword-arguments/53380