-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
stubtest: basic support for unpack kwargs #21024
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -60,6 +60,7 @@ def __getitem__(self, typeargs: Any) -> object: ... | |||||||||||||||
| Final = 0 | ||||||||||||||||
| Literal = 0 | ||||||||||||||||
| TypedDict = 0 | ||||||||||||||||
| Unpack = 0 | ||||||||||||||||
|
|
||||||||||||||||
| class TypeVar: | ||||||||||||||||
| def __init__(self, name, covariant: bool = ..., contravariant: bool = ...) -> None: ... | ||||||||||||||||
|
|
@@ -765,6 +766,27 @@ def test_varargs_varkwargs(self) -> Iterator[Case]: | |||||||||||||||
| error="k6", | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| @collect_cases | ||||||||||||||||
| def test_kwargs_unpack_typeddict(self) -> Iterator[Case]: | ||||||||||||||||
| yield Case( | ||||||||||||||||
| stub=""" | ||||||||||||||||
| from typing import TypedDict, Unpack | ||||||||||||||||
|
|
||||||||||||||||
| class _Args(TypedDict): | ||||||||||||||||
|
Comment on lines
+773
to
+775
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So that I won't have to update #19574 again :-)
Suggested change
|
||||||||||||||||
| a: int | ||||||||||||||||
| b: int | ||||||||||||||||
|
|
||||||||||||||||
| def f1(**kwargs: Unpack[_Args]) -> None: ... | ||||||||||||||||
| """, | ||||||||||||||||
| runtime="def f1(*, a, b): pass", | ||||||||||||||||
| error=None, | ||||||||||||||||
| ) | ||||||||||||||||
| yield Case( | ||||||||||||||||
| stub="def f2(**kwargs: Unpack[_Args]) -> None: ...", | ||||||||||||||||
| runtime="def f2(*, a, c): pass", | ||||||||||||||||
| error="f2", | ||||||||||||||||
| ) | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest adding some cases for mismatched optional parameters (e.g. optional in the TypedDict but required at runtime, and vice versa) |
||||||||||||||||
|
|
||||||||||||||||
| @collect_cases | ||||||||||||||||
| def test_overload(self) -> Iterator[Case]: | ||||||||||||||||
| yield Case( | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing this locally, I think you need to set
kindtoARG_NAMED_OPTtoo for optional parameters to be handled correctly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I'm also not sure if setting
initializer=nodes.EllipsisExpr()is necessary. I wasn't able to find a difference between usingEllipsisExprvs always usingNone)