gh-137786: fix error msg for *args, **kwargs default value#137793
gh-137786: fix error msg for *args, **kwargs default value#137793hnnynh wants to merge 2 commits into
Conversation
| ... 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.
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.
| ... 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.
Same as above, but this is worse -- it confuses the reader over {} (which is not immutable) vs the default (which notionally is).
AA-Turner
left a comment
There was a problem hiding this comment.
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? |
| >>> 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.
| 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'): passanddef func(**kwargs='Hello'): passshould explain more clearly #137786