GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-40334: produce specialised errors for del by hauntsaninja · Pull Request #19911 · python/cpython

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.

Sign up for GitHub

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
gvanrossum merged 12 commits into python:master from hauntsaninja:del
May 11, 2020

Uh oh!

There was an error while loading. Please reload this page.

Merged

bpo-40334: produce specialised errors for del #19911

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
12 commits
Select commit Hold shift + click to select a range
c2219f7
pegen: produce specialised messages for del
May 4, 2020
343ccb5
pegen: further improve del error messages
May 4, 2020
4029ee5
del: add more tests
May 4, 2020
f6b219f
pegen: fix del error messages for binary ops and others
May 5, 2020
9b11bed
pegen: add doctest back in
May 5, 2020
8b4ead5
grammar: reorder and add comment
May 5, 2020
fa21224
del: add even more tests
May 5, 2020
d101ac1
pegen: fix more del test cases
May 5, 2020
850ba88
grammar: reuse del_target_end in invalid_del_target
May 5, 2020
461fe85
grammar: add ENDMARKER to del_target_end
May 5, 2020
d462df9
Revert "grammar: add ENDMARKER to del_target_end"
May 11, 2020
566745e
make regen-pegen
May 11, 2020
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

13 changes: 10 additions & 3 deletions 13 Grammar/python.gram
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
hauntsaninja marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.


targets[asdl_seq*]: a=','.target+ [','] { a }
target[expr_ty] (memo):
Expand Down Expand Up @@ -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)) }
17 changes: 17 additions & 0 deletions 17 Lib/test/test_grammar.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,23 @@ def test_del_stmt(self):
del abc
del x, y, (z, xyz)

x, y, z = "xyz"
del x
del y,
del (z)
del ()

a, b, c, d, e, f, g = "abcdefg"
del a, (b, c), (d, (e, f))

a, b, c, d, e, f, g = "abcdefg"
del a, [b, c], (d, [e, f])

abcd = list("abcd")
del abcd[1:2]

compile("del a, (b[0].c, (d.e, f.g[1:2])), [h.i.j], ()", "<testcase>", "exec")

def test_pass_stmt(self):
# 'pass'
pass
Expand Down
41 changes: 33 additions & 8 deletions 41 Lib/test/test_syntax.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@
Traceback (most recent call last):
SyntaxError: cannot assign to function call

# Pegen does not support this yet
# >>> del f()
# Traceback (most recent call last):
# SyntaxError: cannot delete function call
>>> del f()
Traceback (most recent call last):
SyntaxError: cannot delete function call

>>> a + 1 = 2
Traceback (most recent call last):
Expand Down Expand Up @@ -665,7 +664,7 @@ def _check_error(self, code, errtext,
self.fail("SyntaxError is not a %s" % subclass.__name__)
mo = re.search(errtext, str(err))
if mo is None:
self.fail("SyntaxError did not contain '%r'" % (errtext,))
self.fail("SyntaxError did not contain %r" % (errtext,))
self.assertEqual(err.filename, filename)
if lineno is not None:
self.assertEqual(err.lineno, lineno)
Expand All @@ -677,10 +676,36 @@ 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 (,)", "invalid syntax")
self._check_error("del 1", "delete literal")
self._check_error("del (1, 2)", "delete literal")
self._check_error("del None", "delete None")
self._check_error("del *x", "delete starred")
self._check_error("del (*x)", "delete starred")
self._check_error("del (*x,)", "delete starred")
self._check_error("del [*x,]", "delete starred")
self._check_error("del f()", "delete function call")
self._check_error("del f(a, b)", "delete function call")
self._check_error("del o.f()", "delete function call")
self._check_error("del a[0]()", "delete function call")
self._check_error("del x, f()", "delete function call")
self._check_error("del f(), x", "delete function call")
self._check_error("del [a, b, ((c), (d,), e.f())]", "delete function call")
self._check_error("del (a if True else b)", "delete conditional")
self._check_error("del +a", "delete operator")
self._check_error("del a, +b", "delete operator")
self._check_error("del a + b", "delete operator")
self._check_error("del (a + b, c)", "delete operator")
self._check_error("del (c[0], a + b)", "delete operator")
self._check_error("del a.b.c + 2", "delete operator")
self._check_error("del a.b.c[0] + 2", "delete operator")
self._check_error("del (a, b, (c, d.e.f + 2))", "delete operator")
self._check_error("del [a, b, (c, d.e.f[0] + 2)]", "delete operator")
self._check_error("del (a := 5)", "delete named expression")
# We don't have a special message for this, but make sure we don't
# report "cannot delete name"
self._check_error("del a += b", "invalid syntax")

def test_global_param_err_first(self):
source = """if 1:
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.