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
Running the code below will produce a SyntaxError with the message: "non-default argument follows default argument".
deftest(a=None, b):
returnbifaisNoneelsea
The issue is that a and b aren't arguments, rather, they are parameters. The error message should be changed to: "non-default parameter follows default parameter".
This change appears simple enough and although it is not something I've found to be troublesome, it will help users to use correct keywords (arguments vs. parameters) when searching on the internet.
The problem is more subtle. The thing is, "default parameter" doesn't make sense in this context. Yes, a and b are parameter, but a is not "default parameter" in any sensible way. It is _None_ which is the default argument for parameter a, while parameter b has no default argument. In other words, if the function weren't called with a first argument, the default argument would be used.
So, the fix should be a bit more complicated. Maybe, "a parameter without a default follows a parameter with a default"?
changed the title [-]"SyntaxError: non-default argument follows default argument" should be "parameter"[/-][+]"SyntaxError: non-default argument follows default argument" confuses[/+]on Mar 19, 2022
changed the title [-]"SyntaxError: non-default argument follows default argument" should be "parameter"[/-][+]"SyntaxError: non-default argument follows default argument" confuses[/+]on Mar 19, 2022
Activity
Bluenix2 commentedon Mar 18, 2022
Running the code below will produce a SyntaxError with the message: "non-default argument follows default argument".
The issue is that
aandbaren't arguments, rather, they are parameters. The error message should be changed to: "non-default parameter follows default parameter".This change appears simple enough and although it is not something I've found to be troublesome, it will help users to use correct keywords (arguments vs. parameters) when searching on the internet.
vedgar commentedon Mar 18, 2022
The problem is more subtle. The thing is, "default parameter" doesn't make sense in this context. Yes, a and b are parameter, but a is not "default parameter" in any sensible way. It is _None_ which is the default argument for parameter a, while parameter b has no default argument. In other words, if the function weren't called with a first argument, the default argument would be used.
So, the fix should be a bit more complicated. Maybe, "a parameter without a default follows a parameter with a default"?
Bluenix2 commentedon Mar 18, 2022
Yes I agree, that would be the best.
terryjreedy commentedon Mar 19, 2022
Current message same in 3.11 and 3.9, but I am not sure about backporting to old parser. However merges a change, if any, can decide.
7 remaining items
[-]"SyntaxError: non-default argument follows default argument" should be "parameter"[/-][+]"SyntaxError: non-default argument follows default argument" confuses[/+][-]"SyntaxError: non-default argument follows default argument" should be "parameter"[/-][+]"SyntaxError: non-default argument follows default argument" confuses[/+]lysnikolaou commentedon Aug 12, 2022
In addition to this, we fall back to the generic
invalid syntaxmessage, in case there are positional-only parameters before the failing ones:@gpshead you still intend to work on this? I can open a PR for it in case you won't.
gpshead commentedon Aug 12, 2022
I've lost track of why I assigned this to myself (I didn't leave myself a comment? tsk tsk), so no, feel free to take it!
pythongh-91210: Improve error message when non-default param follows …
gh-91210: Improve error message when non-default param follows default (
hauntsaninja commentedon Oct 12, 2022
Thanks, looks like this has been fixed :-)