Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3d18034

Browse files
authored
gh-110696: Fix incorrect syntax error message for incorrect argument unpacking (#110706)
1 parentec5622d commit3d18034

File tree

4 files changed

+1539
-1173
lines changed

4 files changed

+1539
-1173
lines changed

‎Grammar/python.gram‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,8 @@ func_type_comment[Token*]:
11281128

11291129
# From here on, there are rules for invalid syntax with specialised error messages
11301130
invalid_arguments:
1131-
| a=args ',' '*' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "iterable argument unpacking follows keyword argument unpacking") }
1131+
| ((','.(starred_expression | ( assignment_expression | expression !':=') !'=')+ ',' kwargs) | kwargs) ',' b='*' {
1132+
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(b, "iterable argument unpacking follows keyword argument unpacking") }
11321133
| a=expression b=for_if_clauses ',' [args | expression for_if_clauses] {
11331134
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, _PyPegen_get_last_comprehension_item(PyPegen_last_item(b, comprehension_ty)), "Generator expression must be parenthesized") }
11341135
| a=NAME b='=' expression for_if_clauses {

‎Lib/test/test_syntax.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,17 @@ def f(x: *b)
19551955
...
19561956
SyntaxError: yield expression cannot be used within the definition of a generic
19571957
1958+
>>> f(**x, *y)
1959+
Traceback (most recent call last):
1960+
SyntaxError: iterable argument unpacking follows keyword argument unpacking
1961+
1962+
>>> f(**x, *)
1963+
Traceback (most recent call last):
1964+
SyntaxError: iterable argument unpacking follows keyword argument unpacking
1965+
1966+
>>> f(x, *:)
1967+
Traceback (most recent call last):
1968+
SyntaxError: invalid syntax
19581969
"""
19591970

19601971
importre
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix incorrect error message for invalid argument unpacking. Patch by Pablo
2+
Galindo

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp