summaryrefslogtreecommitdiffstats
path: root/Grammar
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2021-01-02 23:14:21 (GMT)
committerGitHub <noreply@github.com>2021-01-02 23:14:21 (GMT)
commit2ea320dddd553298038bb7d6789e50e199332f66 (patch)
treee0388038b94c848cc18922f86ff0cb82e4c44465 /Grammar
parent8f8de7380cd7fee4972a10240ad2b0fdc332b14d (diff)
downloadcpython-2ea320dddd553298038bb7d6789e50e199332f66.zip
cpython-2ea320dddd553298038bb7d6789e50e199332f66.tar.gz
cpython-2ea320dddd553298038bb7d6789e50e199332f66.tar.bz2
bpo-40631: Disallow single parenthesized star target (GH-24027)
Diffstat (limited to 'Grammar')
-rw-r--r--Grammar/python.gram13
1 files changed, 9 insertions, 4 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram
index 4915cc4..8517bf2 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -580,18 +580,23 @@ star_targets[expr_ty]:
| a=star_target !',' { a }
| a=star_target b=(',' c=star_target { c })* [','] {
_Py_Tuple(CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)), Store, EXTRA) }
-star_targets_seq[asdl_expr_seq*]: a[asdl_expr_seq*]=','.star_target+ [','] { a }
+star_targets_list_seq[asdl_expr_seq*]: a[asdl_expr_seq*]=','.star_target+ [','] { a }
+star_targets_tuple_seq[asdl_expr_seq*]:
+ | a=star_target b=(',' c=star_target { c })+ [','] { (asdl_expr_seq*) _PyPegen_seq_insert_in_front(p, a, b) }
+ | a=star_target ',' { (asdl_expr_seq*) _PyPegen_singleton_seq(p, a) }
star_target[expr_ty] (memo):
| '*' a=(!'*' star_target) {
_Py_Starred(CHECK(expr_ty, _PyPegen_set_expr_context(p, a, Store)), Store, EXTRA) }
+ | target_with_star_atom
+target_with_star_atom[expr_ty] (memo):
| a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Store, EXTRA) }
| a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) }
| star_atom
star_atom[expr_ty]:
| a=NAME { _PyPegen_set_expr_context(p, a, Store) }
- | '(' a=star_target ')' { _PyPegen_set_expr_context(p, a, Store) }
- | '(' a=[star_targets_seq] ')' { _Py_Tuple(a, Store, EXTRA) }
- | '[' a=[star_targets_seq] ']' { _Py_List(a, Store, EXTRA) }
+ | '(' a=target_with_star_atom ')' { _PyPegen_set_expr_context(p, a, Store) }
+ | '(' a=[star_targets_tuple_seq] ')' { _Py_Tuple(a, Store, EXTRA) }
+ | '[' a=[star_targets_list_seq] ']' { _Py_List(a, Store, EXTRA) }
single_target[expr_ty]:
| single_subscript_attribute_target