mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
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.
This commit is contained in:
parent
b678de8ba6
commit
99a5023c80
3 changed files with 33 additions and 2 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue