mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-90994: Improve error messages upon call arguments syntax errors (GH-96893)
This commit is contained in:
parent
e13d1d9dda
commit
6d8da238cc
4 changed files with 3407 additions and 3129 deletions
|
@ -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") }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue