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
Prev Previous commit
Next Next commit
del: add more tests
  • Loading branch information
hauntsaninja committed May 11, 2020
commit 4029ee5a1b27dca4a065f507b976b79e69a39e51
16 changes: 16 additions & 0 deletions Lib/test/test_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,22 @@ def test_del_stmt(self):
del abc
del x, y, (z, xyz)

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

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
27 changes: 23 additions & 4 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,29 @@ def test_assign_call(self):
self._check_error("f() = 1", "assign")

def test_assign_del(self):
self._check_error("del f()", "delete")
self._check_error("del 1", "delete")
self._check_error("del *x", "delete")
self._check_error("del x, f()", "delete")
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 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 := 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
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