aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2020-05-07 13:44:06 +0300
committerGitHub <noreply@github.com>2020-05-07 11:44:06 +0100
commit4638c6429575bd6de26b12b2af5df74d6568b553 (patch)
treedb027fceca158090caf8f194fc577d6631f82daa /Grammar
parentbpo-40334: Fix error location upon parsing an invalid string literal (GH-19962) (diff)
downloadcpython-4638c6429575bd6de26b12b2af5df74d6568b553.tar.gz
cpython-4638c6429575bd6de26b12b2af5df74d6568b553.tar.bz2
cpython-4638c6429575bd6de26b12b2af5df74d6568b553.zip
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.gram4
1 files changed, 4 insertions, 0 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram
index 3d8a39b1d59..574e1e14216 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)) }