You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The error messages of def func(*args='Hello'): pass and def func(**kwargs='Hello'): pass should explain more clearly #137786
Then, setting a default value to *args and **kwargs gets the error messages as shown below. I think the error messages should explain more clearly because Python doc doesn't explain *args and **kwargs are the optional parameters which have the immutable default values () and {} respectively and var-keyword argument and var-keyword argument should be var-keyword parameter and var-keyword parameter:
deffunc(*args='Hello'):
pass# Error
SyntaxError: var-positional argument cannot have default value
deffunc(**kwargs='Hello'):
pass# Error
SyntaxError: var-keyword argument cannot have default value
So, the error messages should be like belolw:
SyntaxError: var-positional parameter's default value cannot be changed because it has the immutable default value ()
SyntaxError: var-keyword parameter's default value cannot be changed because it has the immutable default value {}
Strictly speaking, error messages are correct. They are talking about default values for parameters, this has clear meaning in the grammar specification. See 8.7. Function definitions:
When one or more parameters have the form parameter = expression, the function is said to have “default parameter values.” For a parameter with a default value, the corresponding argument may be omitted from a call, in which case the parameter’s default value is substituted.
I suggest to close this.
Reacted by Adam Turner, adam j hartz and Serhiy Storchaka
There was an error in these error messages -- the term "argument" was misused instead of "parameter". This is perhaps the reason of your confusion. But this was fixed in #133379.
Activity
hnnynh commentedon Aug 15, 2025
Looks Interesting! @corona10 Can you assign this issue to me? It may take some time as this is my first time, but I will do my best. 🚀
corona10 commentedon Aug 15, 2025
Yeah please go a head!
corona10 commentedon Aug 15, 2025
@hnnynh Maybe worth to start here:
cpython/Grammar/python.gram
Line 1338 in 8665769
skirpichev commentedon Aug 15, 2025
Strictly speaking, error messages are correct. They are talking about default values for parameters, this has clear meaning in the grammar specification. See 8.7. Function definitions:
I suggest to close this.
skirpichev commentedon Aug 15, 2025
CC @pablogsal, as this related to parser
hnnynh commentedon Aug 15, 2025
I thought adding a reason to this message would help users better understand the error.
If the issue is closed, I will close the PR as well.
serhiy-storchaka commentedon Aug 15, 2025
I think that the current error messages are pretty clear. The proposed error messages are confusing and simply incorrect.
serhiy-storchaka commentedon Aug 15, 2025
There was an error in these error messages -- the term "argument" was misused instead of "parameter". This is perhaps the reason of your confusion. But this was fixed in #133379.
corona10 commentedon Aug 15, 2025
Looks like it is not worth to fixing it. Let's close the issue :) Thanks for the effort @hnnynh