-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Accept empty list unpacking for function without parameter #7392
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
Accept empty list unpacking for function without parameter #7392
Conversation
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.
Thanks for fixing this! The fix looks good, just a few small comments.
mypy/checkexpr.py
Outdated
@@ -3833,9 +3833,9 @@ def is_async_def(t: Type) -> bool: | |||
return isinstance(t, Instance) and t.type.fullname() == 'typing.Coroutine' | |||
|
|||
|
|||
def is_empty_tuple(t: Type) -> bool: | |||
def is_not_empty_tuple(t: Type) -> bool: |
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 was a little confused by the name at first. What about renaming this to is_non_empty_tuple
?
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.
Fixed.
@@ -448,6 +447,15 @@ def f(x: int, *, y: str) -> None: pass | |||
f(y='x', *(1,)) | |||
[builtins fixtures/list.pyi] | |||
|
|||
[case testVarArgsEmptyList] |
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 assume that there's an existing test case that covers the empty tuple 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.
Actually, there is not. I thought that a tuple test is not in the scope of this PR.
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.
Since this changes the code related to handling empty/non-empty tuples as *args
, it would be good to add a test case for this in case one doesn't exist already. This would validate that the change hasn't introduced a regression.
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.
Added.
mypy/checkexpr.py
Outdated
@@ -1233,7 +1233,7 @@ def check_for_extra_actual_arguments(self, | |||
for i, kind in enumerate(actual_kinds): | |||
if i not in all_actuals and ( | |||
kind != nodes.ARG_STAR or | |||
not is_empty_tuple(actual_types[i])): | |||
is_not_empty_tuple(actual_types[i])): |
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.
Here it would be nice to add a comment about list and Any
star args potentially being empty, so we don't complain about them.
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 added the comment.
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.
Thanks!
Fixes #4997.