diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-11-19 22:54:57 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-11-19 22:54:57 (GMT) |
commit | 99a5023c80d9a690e4305e2ded1b2a9cf6b30251 (patch) | |
tree | 3fb07d09a0ba874e6607b11b1ad9cc55515c1daa /Lib | |
parent | b678de8ba643d940009f26d50d3f6014305f152c (diff) | |
download | cpython-99a5023c80d9a690e4305e2ded1b2a9cf6b30251.zip cpython-99a5023c80d9a690e4305e2ded1b2a9cf6b30251.tar.gz cpython-99a5023c80d9a690e4305e2ded1b2a9cf6b30251.tar.bz2 |
improve several corner cases related with argument names in parenthesis
- Fix #7362: give a good error message for parenthesized arguments with
defaults.
- Add a py3k warning for any parenthesized arguments since those are not allowed
in Py3. This warning is not given in tuple unpacking, since that incurs the
tuple unpacking warning.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_py3kwarn.py | 12 | ||||
-rw-r--r-- | Lib/test/test_syntax.py | 6 |
2 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_py3kwarn.py b/Lib/test/test_py3kwarn.py index c7fdd6b..d754faa 100644 --- a/Lib/test/test_py3kwarn.py +++ b/Lib/test/test_py3kwarn.py @@ -30,6 +30,18 @@ class TestPy3KWarnings(unittest.TestCase): exec "`2`" in {} self.assertWarning(None, w, expected) + def test_paren_arg_names(self): + expected = 'parenthesized argument names are invalid in 3.x' + def check(s): + exec s in {} + self.assertWarning(None, w, expected) + with check_warnings() as w: + check("def f((x)): pass") + check("def f((((x))), (y)): pass") + check("def f((x), (((y))), m=32): pass") + # Something like def f((a, (b))): pass will raise the tuple + # unpacking warning. + def test_forbidden_names(self): # So we don't screw up our globals def safe_exec(expr): diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index 26d78ad..2118c62 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -493,10 +493,14 @@ 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("%s did not contain '%r'" % (err, errtext,)) else: self.fail("compile() did not raise SyntaxError") + def test_paren_arg_with_default(self): + self._check_error("def f((x)=23): pass", + "parenthesized arg with default") + def test_assign_call(self): self._check_error("f() = 1", "assign") |