Skip to content

Commit

Permalink
pythongh-110696: Fix incorrect syntax error message for incorrect arg…
Browse files Browse the repository at this point in the history
…ument unpacking (python#110706)
  • Loading branch information
pablogsal authored Oct 12, 2023
1 parent ec5622d commit 3d18034
Show file tree
Hide file tree
Showing 4 changed files with 1,539 additions and 1,173 deletions.
3 changes: 2 additions & 1 deletion Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,8 @@ func_type_comment[Token*]:

# From here on, there are rules for invalid syntax with specialised error messages
invalid_arguments:
| a=args ',' '*' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "iterable argument unpacking follows keyword argument unpacking") }
| ((','.(starred_expression | ( assignment_expression | expression !':=') !'=')+ ',' kwargs) | kwargs) ',' b='*' {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(b, "iterable argument unpacking follows keyword argument unpacking") }
| a=expression b=for_if_clauses ',' [args | expression for_if_clauses] {
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, _PyPegen_get_last_comprehension_item(PyPegen_last_item(b, comprehension_ty)), "Generator expression must be parenthesized") }
| a=NAME b='=' expression for_if_clauses {
Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -1955,6 +1955,17 @@ def f(x: *b)
...
SyntaxError: yield expression cannot be used within the definition of a generic
>>> f(**x, *y)
Traceback (most recent call last):
SyntaxError: iterable argument unpacking follows keyword argument unpacking
>>> f(**x, *)
Traceback (most recent call last):
SyntaxError: iterable argument unpacking follows keyword argument unpacking
>>> f(x, *:)
Traceback (most recent call last):
SyntaxError: invalid syntax
"""

import re
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix incorrect error message for invalid argument unpacking. Patch by Pablo
Galindo
Loading

0 comments on commit 3d18034

Please sign in to comment.