Skip to content

Commit f4fcdb6

Browse files
committed
warn about parameter tuple unpacking
1 parent d5efd20 commit f4fcdb6

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

Lib/test/test_py3kwarn.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ def set():
173173
with catch_warning() as w:
174174
self.assertWarning(set(), w, expected)
175175

176+
def test_tuple_parameter_unpacking(self):
177+
expected = "tuple parameter unpacking has been removed in 3.x"
178+
with catch_warning() as w:
179+
exec "def f((a, b)): pass"
180+
self.assertWarning(None, w, expected)
181+
176182
def test_buffer(self):
177183
expected = 'buffer() not supported in 3.x; use memoryview()'
178184
with catch_warning() as w:

Python/ast.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,9 @@ ast_for_arguments(struct compiling *c, const node *n)
701701
/* def foo((x)): is not complex, special case. */
702702
if (NCH(ch) != 1) {
703703
/* We have complex arguments, setup for unpacking. */
704+
if (Py_Py3kWarningFlag && !ast_warn(c, ch,
705+
"tuple parameter unpacking has been removed in 3.x"))
706+
goto error;
704707
asdl_seq_SET(args, k++, compiler_complex_args(c, ch));
705708
if (!asdl_seq_GET(args, k-1))
706709
goto error;

0 commit comments

Comments
 (0)