diff options
author | Lysandros Nikolaou <lisandrosnik@gmail.com> | 2022-11-20 23:15:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-20 23:15:05 (GMT) |
commit | 6d8da238ccdf946dc90e20821652d8caa25b76ba (patch) | |
tree | e19f5e842751c4070c775f3a5b929d3d05d2dfc3 /Grammar | |
parent | e13d1d9dda8c27691180bc618bd5e9bf43dfa89f (diff) | |
download | cpython-6d8da238ccdf946dc90e20821652d8caa25b76ba.zip cpython-6d8da238ccdf946dc90e20821652d8caa25b76ba.tar.gz cpython-6d8da238ccdf946dc90e20821652d8caa25b76ba.tar.bz2 |
gh-90994: Improve error messages upon call arguments syntax errors (GH-96893)
Diffstat (limited to 'Grammar')
-rw-r--r-- | Grammar/python.gram | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram index 787fbad..2498251 100644 --- a/Grammar/python.gram +++ b/Grammar/python.gram @@ -957,6 +957,7 @@ kwargs[asdl_seq*]: | ','.kwarg_or_double_starred+ starred_expression[expr_ty]: + | invalid_starred_expression | '*' a=expression { _PyAST_Starred(a, Load, EXTRA) } kwarg_or_starred[KeywordOrStarred*]: @@ -1083,6 +1084,8 @@ invalid_arguments: 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 { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Maybe you meant '==' or ':=' instead of '='?")} + | (args ',')? a=NAME b='=' &(',' | ')') { + RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "expected argument value expression")} | a=args b=for_if_clauses { _PyPegen_nonparen_genexp_in_call(p, a, b) } | args ',' a=expression b=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") } @@ -1095,6 +1098,8 @@ invalid_kwarg: | !(NAME '=') a=expression b='=' { RAISE_SYNTAX_ERROR_KNOWN_RANGE( a, b, "expression cannot contain assignment, perhaps you meant \"==\"?") } + | a='**' expression '=' b=expression { + RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "cannot assign to keyword argument unpacking") } # IMPORTANT: Note that the "_without_invalid" suffix causes the rule to not call invalid rules under it expression_without_invalid[expr_ty]: @@ -1328,3 +1333,5 @@ invalid_kvpair: RAISE_ERROR_KNOWN_LOCATION(p, PyExc_SyntaxError, a->lineno, a->end_col_offset - 1, a->end_lineno, -1, "':' expected after dictionary key") } | expression ':' a='*' bitwise_or { RAISE_SYNTAX_ERROR_STARTING_FROM(a, "cannot use a starred expression in a dictionary value") } | 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") } |