Skip to content

bpo-40334: produce specialised errors for del #19911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 11, 2020
Next Next commit
pegen: produce specialised messages for del
  • Loading branch information
hauntsaninja committed May 11, 2020
commit c2219f76aca0cd1ee044dd34c0afbcc599315c2d
9 changes: 7 additions & 2 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ yield_stmt[stmt_ty]: y=yield_expr { _Py_Expr(y, EXTRA) }

assert_stmt[stmt_ty]: 'assert' a=expression b=[',' z=expression { z }] { _Py_Assert(a, b, EXTRA) }

del_stmt[stmt_ty]: 'del' a=del_targets { _Py_Delete(a, EXTRA) }
del_stmt[stmt_ty]:
| 'del' a=del_targets { _Py_Delete(a, EXTRA) }
| invalid_delete

import_stmt[stmt_ty]: import_name | import_from
import_name[stmt_ty]: 'import' a=dotted_as_names { _Py_Import(a, EXTRA) }
Expand Down Expand Up @@ -588,7 +590,7 @@ del_target[expr_ty] (memo):
| a=t_primary '[' b=slices ']' !t_lookahead { _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 !t_lookahead { _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) }
Expand Down Expand Up @@ -649,3 +651,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_delete:
| 'del' a=star_expressions {
RAISE_SYNTAX_ERROR_NO_COL_OFFSET("cannot delete %s", _PyPegen_get_expr_name(a)) }
4 changes: 2 additions & 2 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,10 +677,10 @@ def _check_error(self, code, errtext,
def test_assign_call(self):
self._check_error("f() = 1", "assign")

@support.skip_if_new_parser("Pegen does not produce a specialized error "
"message yet")
def test_assign_del(self):
self._check_error("del f()", "delete")
self._check_error("del 1", "delete")
self._check_error("del *x", "delete")

def test_global_param_err_first(self):
source = """if 1:
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy