Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,8 @@ invalid_parameters:
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "/ must be ahead of *") }
| param_maybe_default+ '/' a='*' {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "expected comma between / and *") }
| a=NAME b=NAME {
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "expected comma between parameters") }
invalid_default:
| a='=' &(')'|',') { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "expected default value expression") }
invalid_star_etc:
Expand Down Expand Up @@ -1344,6 +1346,8 @@ invalid_lambda_parameters:
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "/ must be ahead of *") }
| lambda_param_maybe_default+ '/' a='*' {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "expected comma between / and *") }
| a=NAME b=NAME {
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "expected comma between parameters") }
invalid_lambda_parameters_helper:
| a=lambda_slash_with_default { _PyPegen_singleton_seq(p, a) }
| lambda_param_with_default+
Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,16 @@
Traceback (most recent call last):
SyntaxError: expected comma between / and *

>>> def foo(a b):
... pass
Traceback (most recent call last):
SyntaxError: expected comma between parameters

>>> def foo(a d=1):
... pass
Traceback (most recent call last):
SyntaxError: expected comma between parameters

>>> def foo(a=1,d=,c):
... pass
Traceback (most recent call last):
Expand Down Expand Up @@ -568,6 +578,10 @@
Traceback (most recent call last):
SyntaxError: expected comma between / and *

>>> lambda a b: None
Traceback (most recent call last):
SyntaxError: expected comma between parameters

>>> lambda a,*b=3,c: None
Traceback (most recent call last):
SyntaxError: var-positional argument cannot have default value
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved error message for missing comma between parameters in function/lambda definition.
56 changes: 56 additions & 0 deletions Parser/parser.c

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

Loading