How to annotate kwargs with Unpack and TypedDict? #1137
-
Consider this example: class Kwargs(TypedDict, total=False):
x: Required[int]
y: Required[int]
z: NotRequired[str]
def foo(**kwargs: Unpack[Kwargs]):
....
foo(x=1) # should be ok
foo(y=1) # should be ok
foo(z=1) # raise error |
Beta Was this translation helpful? Give feedback.
Answered by
JelleZijlstra
Apr 15, 2022
Replies: 1 comment 5 replies
-
This isn't something you can do with a TypedDict, and I don't think the upcoming PEP for TypedDict + kwargs will support it. You should use overloads instead. |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
q0w
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This isn't something you can do with a TypedDict, and I don't think the upcoming PEP for TypedDict + kwargs will support it. You should use overloads instead.