diff options
author | Lysandros Nikolaou <lisandrosnik@gmail.com> | 2020-05-07 10:44:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-07 10:44:06 (GMT) |
commit | 4638c6429575bd6de26b12b2af5df74d6568b553 (patch) | |
tree | db027fceca158090caf8f194fc577d6631f82daa /Grammar | |
parent | 2f37c355ab0e9ec9c1753985d27c41fa0bd719b9 (diff) | |
download | cpython-4638c6429575bd6de26b12b2af5df74d6568b553.zip cpython-4638c6429575bd6de26b12b2af5df74d6568b553.tar.gz cpython-4638c6429575bd6de26b12b2af5df74d6568b553.tar.bz2 |
bpo-40334: Error message for invalid default args in function call (GH-19973)
When parsing something like `f(g()=2)`, where the name of a default arg
is not a NAME, but an arbitrary expression, a specialised error message
is emitted.
Diffstat (limited to 'Grammar')
-rw-r--r-- | Grammar/python.gram | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram index 3d8a39b..574e1e1 100644 --- a/Grammar/python.gram +++ b/Grammar/python.gram @@ -548,10 +548,12 @@ kwarg_or_starred[KeywordOrStarred*]: | a=NAME '=' b=expression { _PyPegen_keyword_or_starred(p, CHECK(_Py_keyword(a->v.Name.id, b, EXTRA)), 1) } | a=starred_expression { _PyPegen_keyword_or_starred(p, a, 0) } + | invalid_kwarg kwarg_or_double_starred[KeywordOrStarred*]: | a=NAME '=' b=expression { _PyPegen_keyword_or_starred(p, CHECK(_Py_keyword(a->v.Name.id, b, EXTRA)), 1) } | '**' a=expression { _PyPegen_keyword_or_starred(p, CHECK(_Py_keyword(NULL, a, EXTRA)), 1) } + | invalid_kwarg # NOTE: star_targets may contain *bitwise_or, targets may not. star_targets[expr_ty]: @@ -620,6 +622,8 @@ incorrect_arguments: | expression for_if_clauses ',' [args | expression for_if_clauses] { RAISE_SYNTAX_ERROR("Generator expression must be parenthesized") } | a=args ',' args { _PyPegen_arguments_parsing_error(p, a) } +invalid_kwarg: + | expression '=' { RAISE_SYNTAX_ERROR("expression cannot contain assignment, perhaps you meant \"==\"?") } invalid_named_expression: | a=expression ':=' expression { RAISE_SYNTAX_ERROR("cannot use assignment expressions with %s", _PyPegen_get_expr_name(a)) } |