summaryrefslogtreecommitdiffstats
path: root/Grammar
diff options
context:
space:
mode:
authorBatuhan Taskaya <batuhanosmantaskaya@gmail.com>2020-06-27 18:33:08 (GMT)
committerGitHub <noreply@github.com>2020-06-27 18:33:08 (GMT)
commitc8f29ad986f8274fc5fbf889bdd2a211878856b9 (patch)
treeb4fdbecd0b5f987ffa160cd966263bd77063a06c /Grammar
parent6dcbc2422de9e2a7ff89a4689572d84001e230b2 (diff)
downloadcpython-c8f29ad986f8274fc5fbf889bdd2a211878856b9.zip
cpython-c8f29ad986f8274fc5fbf889bdd2a211878856b9.tar.gz
cpython-c8f29ad986f8274fc5fbf889bdd2a211878856b9.tar.bz2
bpo-40769: Allow extra surrounding parentheses for invalid annotated assignment rule (GH-20387)
Diffstat (limited to 'Grammar')
-rw-r--r--Grammar/python.gram12
1 files changed, 10 insertions, 2 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram
index 652f0db..1cba114 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -646,8 +646,12 @@ invalid_named_expression:
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
a, "cannot use assignment expressions with %s", _PyPegen_get_expr_name(a)) }
invalid_assignment:
- | a=list ':' expression { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not list) can be annotated") }
- | a=tuple ':' expression { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") }
+ | a=invalid_ann_assign_target ':' expression {
+ RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
+ a,
+ "only single target (not %s) can be annotated",
+ _PyPegen_get_expr_name(a)
+ )}
| a=star_named_expression ',' star_named_expressions* ':' expression {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") }
| a=expression ':' expression {
@@ -661,6 +665,10 @@ invalid_assignment:
"'%s' is an illegal expression for augmented assignment",
_PyPegen_get_expr_name(a)
)}
+invalid_ann_assign_target[expr_ty]:
+ | list
+ | tuple
+ | '(' a=invalid_ann_assign_target ')' { a }
invalid_del_stmt:
| 'del' a=star_expressions {
RAISE_SYNTAX_ERROR_INVALID_TARGET(DEL_TARGETS, a) }