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
SyntaxError: parameter without a default follows parameter with a default is inaccurate #129545
Trying to define a function in which a positional parameter follows a parameter with a default value, we get a SyntaxError as expected:
>>> deff(a=1, b):
File "<python-input-0>", line 1
def f(a=1, b):
^
SyntaxError: parameter without a default follows parameter with a default
But the message that comes with it is not as accurate as it could be, as we can easily construct a valid function signature in which a parameter without a default follows a parameter with a default so long as both are keyword-only parameters:
>>> deff(*, a=1, b):
... pass
...
>>>
(I didn't use a=1, *, b for this counterexample because then one could argue that, if "follows" is interpreted as "follows immediately", we did resolve the situation described in the error message, making it formally accurate, albeit confusing.)
Proposed fix
So, in my opinion, the message should be changed to something more like positional parameter without a default follows parameter with a default, reflecting the true nature of the problem.
Other benefits
It's not just a matter of accuracy for accuracy's sake, however: This change would also hint to people who don't know or have forgotten about keyword-only parameters that there is another possibility of resolving the issue than the ones implied by the current message.
Keyword-only parameters were introduced in Python 3.0 with PEP 3102, which makes me think I must be missing some obvious reason why their consequences can't be reflected in the error message.
dataclasses has an exception message with the same issue, but as that one also still has the "argument" vs "parameter" issue mentioned above, it's probably appropriate to create a separate ticket for that.
Activity
sharktide commentedon Mar 6, 2025
I'll work on it
pythongh-129545 Enhance error messages
sharktide commentedon Mar 7, 2025
Finished the code and tested, will make a pr when I have time
lysnikolaou commentedon May 8, 2025
Closing this as won't fix. Rationale in the PR. Thanks for the issue though @smheidrich!