This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: "SyntaxError: non-default argument follows default argument" confuses
Type: behavior Stage: patch review
Components: Interpreter Core Versions: Python 3.11, Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: gregory.p.smith Nosy List: bluenix, gregory.p.smith, pablogsal, terry.reedy, veky
Priority: normal Keywords: patch

Created on 2022-03-18 01:17 by bluenix, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 32014 open gregory.p.smith, 2022-03-20 21:16
Messages (4)
msg415463 - (view) Author: Bluenix (bluenix) * Date: 2022-03-18 01:17
Running the code below will produce a SyntaxError with the message: "non-default argument follows default argument".

    def test(a=None, b):
        return b if a is None else a

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.
msg415469 - (view) Author: Vedran Čačić (veky) * Date: 2022-03-18 04:48
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"?
msg415526 - (view) Author: Bluenix (bluenix) * Date: 2022-03-18 20:37
Yes I agree, that would be the best.
msg415530 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-03-19 00:45
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.
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91210
2022-03-20 21:18:26gregory.p.smithsetassignee: gregory.p.smith
2022-03-20 21:16:18gregory.p.smithsetkeywords: + patch
nosy: + gregory.p.smith

pull_requests: + pull_request30102
stage: needs patch -> patch review
2022-03-19 00:46:08terry.reedysettitle: "SyntaxError: non-default argument follows default argument" should be "parameter" -> "SyntaxError: non-default argument follows default argument" confuses
2022-03-19 00:45:41terry.reedysetversions: + Python 3.11, - Python 3.7, Python 3.8, Python 3.9
nosy: + pablogsal, terry.reedy

messages: + msg415530

type: behavior
stage: needs patch
2022-03-18 20:37:06bluenixsetmessages: + msg415526
2022-03-18 04:48:34vekysetnosy: + veky
messages: + msg415469
2022-03-18 01:17:42bluenixcreate