-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
gh-137786: fix error msg for *args, **kwargs default value #137793
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
Conversation
Lib/test/test_syntax.py
Outdated
@@ -461,22 +461,22 @@ | |||
>>> def foo(a,*b=3,c): | |||
... pass | |||
Traceback (most recent call last): | |||
SyntaxError: var-positional parameter cannot have default value | |||
SyntaxError: var-positional parameter's default value cannot be changed because it has the immutable default value () |
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 don't think this is clearer. "var-positional parameter cannot have default value" is oddly worded but I think equal or better to this proposal.
Lib/test/test_syntax.py
Outdated
>>> def foo(a,**b=3): | ||
... pass | ||
Traceback (most recent call last): | ||
SyntaxError: var-keyword parameter cannot have default value | ||
SyntaxError: var-keyword parameter's default value cannot be changed because it has the immutable default value {} |
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.
Same as above, but this is worse -- it confuses the reader over {}
(which is not immutable) vs the default (which notionally is).
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.
Instead of adding "it has immutable default X", I would focus on the start of the error message -- we could use friendlier terms than "var-positional" or "var-keyword". I think the changes to the end of the message are unhelpful at best just as they make it longer.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
@AA-Turner, see issue thread. Could you explain why there is an issue at all? |
Lib/test/test_syntax.py
Outdated
@@ -577,11 +577,11 @@ | |||
>>> lambda a,*b=3,c: None | |||
Traceback (most recent call last): | |||
SyntaxError: var-positional parameter cannot have default value | |||
SyntaxError: var-positional parameter's default value cannot be changed because it has the immutable default value () |
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.
SyntaxError: var-positional parameter's default value cannot be changed because it has the immutable default value () | |
SyntaxError: Cannot change the default value of a var-positional parameter because it is already defined. |
@AA-Turner Maybe this would make more sense to people?
For me, “immutable default value” feels too detailed, and the current message isn’t very user-friendly.
I agree with the comment that the original error messages are correct, but I'd like to suggest adding explanations that are easy for users to understand. |
@hnnynh, please avoid force-pushes. Don't alter git history. |
I made force-pushes just to update the message. I’ll ensure future changes are committed properly. |
Just add a new commit. All commits will be squashed on merge. If you wish to suggest core developers the final commit message - please edit pr title/description. |
The issue is closed, so I will close the PR as well. Thank you for discussing this with me. And I appreciate your attentions and comments. |
According to #137786 (comment), it might not worth to update message :) Thanks for all efforts @hnnynh , looking forward other PRs in the future! |
Patch for the Issue: #137786
def func(*args='Hello'): pass
anddef func(**kwargs='Hello'): pass
should explain more clearly #137786