Skip to content

gh-133436: Correct error messages that incorrectly use "arguments" #133463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -1319,11 +1319,11 @@ invalid_parameters:
invalid_default:
| a='=' &(')'|',') { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "expected default value expression") }
invalid_star_etc:
| a='*' (')' | ',' (')' | '**')) { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "named arguments must follow bare *") }
| a='*' (')' | ',' (')' | '**')) { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "named parameters must follow bare *") }
| '*' ',' TYPE_COMMENT { RAISE_SYNTAX_ERROR("bare * has associated type comment") }
| '*' param a='=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "var-positional argument cannot have default value") }
| '*' (param_no_default | ',') param_maybe_default* a='*' (param_no_default | ',') {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "* argument may appear only once") }
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "* marker may appear only once") }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked @picnixz suggestion though there may be an even better word?

Copy link

@Kivooeo Kivooeo May 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo, "an asterisk may appear only once" is as clear as possible and will not cause any confusion in terms of terminology

invalid_kwds:
| '**' param a='=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "var-keyword argument cannot have default value") }
| '**' param ',' a=param { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "arguments cannot follow var-keyword argument") }
Expand All @@ -1348,7 +1348,7 @@ invalid_lambda_parameters_helper:
| a=lambda_slash_with_default { _PyPegen_singleton_seq(p, a) }
| lambda_param_with_default+
invalid_lambda_star_etc:
| '*' (':' | ',' (':' | '**')) { RAISE_SYNTAX_ERROR("named arguments must follow bare *") }
| '*' (':' | ',' (':' | '**')) { RAISE_SYNTAX_ERROR("named parameters must follow bare *") }
| '*' lambda_param a='=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "var-positional argument cannot have default value") }
| '*' (lambda_param_no_default | ',') lambda_param_maybe_default* a='*' (lambda_param_no_default | ',') {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "* argument may appear only once") }
Expand Down
18 changes: 9 additions & 9 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,22 +499,22 @@
>>> def foo(*b,*d):
... pass
Traceback (most recent call last):
SyntaxError: * argument may appear only once
SyntaxError: * marker may appear only once

>>> def foo(a,*b,c,*d,*e,c):
... pass
Traceback (most recent call last):
SyntaxError: * argument may appear only once
SyntaxError: * marker may appear only once

>>> def foo(a,b,/,c,*b,c,*d,*e,c):
... pass
Traceback (most recent call last):
SyntaxError: * argument may appear only once
SyntaxError: * marker may appear only once

>>> def foo(a,b,/,c,*b,c,*d,**e):
... pass
Traceback (most recent call last):
SyntaxError: * argument may appear only once
SyntaxError: * marker may appear only once

>>> def foo(a=1,/*,b,c):
... pass
Expand Down Expand Up @@ -598,19 +598,19 @@

>>> lambda *b,*d: None
Traceback (most recent call last):
SyntaxError: * argument may appear only once
SyntaxError: * marker may appear only once

>>> lambda a,*b,c,*d,*e,c: None
Traceback (most recent call last):
SyntaxError: * argument may appear only once
SyntaxError: * marker may appear only once

>>> lambda a,b,/,c,*b,c,*d,*e,c: None
Traceback (most recent call last):
SyntaxError: * argument may appear only once
SyntaxError: * marker may appear only once

>>> lambda a,b,/,c,*b,c,*d,**e: None
Traceback (most recent call last):
SyntaxError: * argument may appear only once
SyntaxError: * marker may appear only once

>>> lambda a=1,d=,c: None
Traceback (most recent call last):
Expand Down Expand Up @@ -2178,7 +2178,7 @@

>>> with (lambda *:0): pass
Traceback (most recent call last):
SyntaxError: named arguments must follow bare *
SyntaxError: named parameters must follow bare *

Corner-cases that used to crash:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correct error messages that incorrectly use "arguments".
6 changes: 3 additions & 3 deletions Parser/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading