diff options
author | Grigoriev Semyon <33061489+grigoriev-semyon@users.noreply.github.com> | 2024-04-02 10:42:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-02 10:42:58 (GMT) |
commit | c97d3af2391e62ef456ef2365d48ab9b8cdbe27b (patch) | |
tree | 0afaf45e907ff189c6a955f7e613211803a10ea8 /Grammar | |
parent | 1d5479b236e9a66dd32a24eff6fb83e3242b999d (diff) | |
download | cpython-c97d3af2391e62ef456ef2365d48ab9b8cdbe27b.zip cpython-c97d3af2391e62ef456ef2365d48ab9b8cdbe27b.tar.gz cpython-c97d3af2391e62ef456ef2365d48ab9b8cdbe27b.tar.bz2 |
gh-109120: Fix syntax error in handlinh of incorrect star expressions (#117444)
Diffstat (limited to 'Grammar')
-rw-r--r-- | Grammar/python.gram | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram index 6966493..9564abf 100644 --- a/Grammar/python.gram +++ b/Grammar/python.gram @@ -1013,6 +1013,7 @@ kwargs[asdl_seq*]: starred_expression[expr_ty]: | invalid_starred_expression | '*' a=expression { _PyAST_Starred(a, Load, EXTRA) } + | '*' { RAISE_SYNTAX_ERROR("Invalid star expression") } kwarg_or_starred[KeywordOrStarred*]: | invalid_kwarg @@ -1133,8 +1134,8 @@ func_type_comment[Token*]: # From here on, there are rules for invalid syntax with specialised error messages invalid_arguments: - | ((','.(starred_expression | ( assignment_expression | expression !':=') !'=')+ ',' kwargs) | kwargs) ',' b='*' { - RAISE_SYNTAX_ERROR_KNOWN_LOCATION(b, "iterable argument unpacking follows keyword argument unpacking") } + | ((','.(starred_expression | ( assignment_expression | expression !':=') !'=')+ ',' kwargs) | kwargs) a=',' ','.(starred_expression !'=')+ { + RAISE_SYNTAX_ERROR_STARTING_FROM(a, "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 { @@ -1396,6 +1397,7 @@ invalid_kvpair: | expression a=':' &('}'|',') {RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "expression expected after dictionary key and ':'") } invalid_starred_expression: | a='*' expression '=' b=expression { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot assign to iterable argument unpacking") } + invalid_replacement_field: | '{' a='=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: valid expression required before '='") } | '{' a='!' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: valid expression required before '!'") } |