Bug report
Bug description:
The problem
Trying to define a function in which a positional parameter follows a parameter with a default value, we get a SyntaxError as expected:
>>> def f(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:
>>> def f(*, 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.
Additional context
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs
Bug report
Bug description:
The problem
Trying to define a function in which a positional parameter follows a parameter with a default value, we get a
SyntaxErroras expected: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:
(I didn't use
a=1, *, bfor 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.
Additional context
non-default argument follows default argumentto the one above starting in Python 3.12 (via gh-91210: Improve error message when non-default param follows default #95933). So there is precedent for changing this message to make it more accurate.dataclasseshas 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.CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs