Skip to content

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

Closed
wants to merge 2 commits into from

Conversation

hnnynh
Copy link

@hnnynh hnnynh commented Aug 15, 2025

@@ -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 ()
Copy link
Member

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.

>>> 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 {}
Copy link
Member

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).

Copy link
Member

@AA-Turner AA-Turner left a 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.

@bedevere-app
Copy link

bedevere-app bot commented Aug 15, 2025

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@skirpichev
Copy link
Contributor

@AA-Turner, see issue thread. Could you explain why there is an issue at all?

@@ -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 ()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

@hnnynh
Copy link
Author

hnnynh commented Aug 15, 2025

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.
So I have updated the messages. Could you please review it?

@skirpichev
Copy link
Contributor

@hnnynh, please avoid force-pushes. Don't alter git history.

@hnnynh
Copy link
Author

hnnynh commented Aug 15, 2025

@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.

@skirpichev
Copy link
Contributor

I made force-pushes just to update the message.

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.

@hnnynh
Copy link
Author

hnnynh commented Aug 15, 2025

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.

@hnnynh hnnynh closed this Aug 15, 2025
@corona10
Copy link
Member

According to #137786 (comment), it might not worth to update message :) Thanks for all efforts @hnnynh , looking forward other PRs in the future!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants