-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prototype support for typed **kwargs
#3002
Comments
There is also a new typing-sig thread about this. I'm glad you're planning to prototype support for this; it's going to be a useful new feature. Here are my thoughts on the questions you posed:
This should be an error.
I assume you mean TypedDict, not TypeVarTuple. I think we should treat it equivalently to a function with the equivalent explicit parameters. For example, these two functions should be equivalent for the purposes of assignabiliity: class TD(TypedDict):
a: int
b: NotRequired[str]
def f1(**kwargs: Unpack[TD]): ...
def f2(*, a: int, b: str = ...): ...
Probably not; it adds a lot of complexity and I don't see a compelling use case.
PEP 646's syntactic changes will not make
I think so. We should treat this new feature the same as any other TypedDict as much as possible, so the type system is more internally consistent.
This should be an error.
I think it should be treated the same as a regular assignment. So if |
This functionality will be included in the next release. |
This is included in pyright 1.1.222, which I just published. It will also be included in the next release of pylance. |
Pylance v2022.2.3 was published on 17/02/2022 two days ago. from typing import TypedDict, Unpack
class MyFuncKwargs(TypedDict):
a: str
b: int
def my_func(**kwargs: Unpack[MyFuncKwargs]) -> None:
return
my_func(a='a', b=1) But obviously I did miss something. ( |
from typing import TypedDict
from typing_extensions import Unpack
class MyFuncKwargs(TypedDict):
a: str
b: int
def my_func(**kwargs: Unpack[MyFuncKwargs]) -> None:
return
my_func(a="a", b=1) |
Many people have requested support for a way to type
**kwargs
with a TypedDict. There have been proposals to support this using theUnpack
type introduced in the recently-accepted PEP 646.It would be good to prototype this to uncover any potential issues.
*
unpack operator introduced in PEP 646?kwargs
within the function implementation? Is it the same as any other TypedDict reference?The text was updated successfully, but these errors were encountered: