summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorShantanu <hauntsaninja@users.noreply.github.com>2020-05-11 21:53:58 (GMT)
committerGitHub <noreply@github.com>2020-05-11 21:53:58 (GMT)
commit27c0d9b54abaa4112d5a317b8aa78b39ad60a808 (patch)
tree94bf73f5275f8156008249528b2997cfee8d47a6 /Lib/test
parent86d69444e7cfe758212956df0be0ec7b8a4251a6 (diff)
downloadcpython-27c0d9b54abaa4112d5a317b8aa78b39ad60a808.zip
cpython-27c0d9b54abaa4112d5a317b8aa78b39ad60a808.tar.gz
cpython-27c0d9b54abaa4112d5a317b8aa78b39ad60a808.tar.bz2
bpo-40334: produce specialized errors for invalid del targets (GH-19911)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_grammar.py17
-rw-r--r--Lib/test/test_syntax.py41
2 files changed, 50 insertions, 8 deletions
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index c24d352..02ba8a8 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -801,6 +801,23 @@ class GrammarTests(unittest.TestCase):
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
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index 0c0fc48..06636ae 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -63,10 +63,9 @@ SyntaxError: cannot assign to __debug__
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):
@@ -665,7 +664,7 @@ class SyntaxTestCase(unittest.TestCase):
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)
@@ -677,10 +676,36 @@ class SyntaxTestCase(unittest.TestCase):
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: