aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShantanu <hauntsaninja@users.noreply.github.com>2020-05-11 14:53:58 -0700
committerGitHub <noreply@github.com>2020-05-11 14:53:58 -0700
commit27c0d9b54abaa4112d5a317b8aa78b39ad60a808 (patch)
tree94bf73f5275f8156008249528b2997cfee8d47a6 /Grammar
parentbpo-40584: Update PyType_FromModuleAndSpec() to process tp_vectorcall_offset ... (diff)
downloadcpython-27c0d9b54abaa4112d5a317b8aa78b39ad60a808.tar.gz
cpython-27c0d9b54abaa4112d5a317b8aa78b39ad60a808.tar.bz2
cpython-27c0d9b54abaa4112d5a317b8aa78b39ad60a808.zip
bpo-40334: produce specialized errors for invalid del targets (GH-19911)
Diffstat (limited to 'Grammar')
-rw-r--r--Grammar/python.gram13
1 files changed, 10 insertions, 3 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram
index 574e1e14216..0542107cac3 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -583,15 +583,19 @@ ann_assign_subscript_attribute_target[expr_ty]:
| a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Store, EXTRA) }
del_targets[asdl_seq*]: a=','.del_target+ [','] { a }
+# The lookaheads to del_target_end ensure that we don't match expressions where a prefix of the
+# expression matches our rule, thereby letting these cases fall through to invalid_del_target.
del_target[expr_ty] (memo):
- | a=t_primary '.' b=NAME !t_lookahead { _Py_Attribute(a, b->v.Name.id, Del, EXTRA) }
- | a=t_primary '[' b=slices ']' !t_lookahead { _Py_Subscript(a, b, Del, EXTRA) }
+ | a=t_primary '.' b=NAME &del_target_end { _Py_Attribute(a, b->v.Name.id, Del, EXTRA) }
+ | a=t_primary '[' b=slices ']' &del_target_end { _Py_Subscript(a, b, Del, EXTRA) }
| del_t_atom
del_t_atom[expr_ty]:
- | a=NAME { _PyPegen_set_expr_context(p, a, Del) }
+ | a=NAME &del_target_end { _PyPegen_set_expr_context(p, a, Del) }
| '(' a=del_target ')' { _PyPegen_set_expr_context(p, a, Del) }
| '(' a=[del_targets] ')' { _Py_Tuple(a, Del, EXTRA) }
| '[' a=[del_targets] ']' { _Py_List(a, Del, EXTRA) }
+ | invalid_del_target
+del_target_end: ')' | ']' | ',' | ';' | NEWLINE
targets[asdl_seq*]: a=','.target+ [','] { a }
target[expr_ty] (memo):
@@ -649,3 +653,6 @@ invalid_lambda_star_etc:
invalid_double_type_comments:
| TYPE_COMMENT NEWLINE TYPE_COMMENT NEWLINE INDENT {
RAISE_SYNTAX_ERROR("Cannot have two type comments on def") }
+invalid_del_target:
+ | a=star_expression &del_target_end {
+ RAISE_SYNTAX_ERROR("cannot delete %s", _PyPegen_get_expr_name(a)) }