I've used python2 for years without even knowing about this feature, but apparently tuple unpacking is supported in function defs:
>>> def foo(a, (b, c)):
... print a, b, c
...
>>> t = (2, 3)
>>> foo(1, t)
1 2 3
Defaults are also allowed, though they seem to be unpacked at function call time and not function def time. And I couldn't figure out how to pass one/any/all of the packed arguments by name, maybe it's impossible.
>>> def foo(a, ((b, c), d)=('xy', 8)):
print a, b, c, d
...
>>> foo(0)
0 x y 8
This is not apparently not just a weird implementation detail: if you read the grammar carefully, in particular what an fpdef
is, you see that function definitions are explicitly designed for tuple unpacking.
My question is, why was this a design choice and what is an example use-case where it's necessary? To me it seems an obscure and error-prone feature that violates zen of python 1, 2, 3, 5, 7, 9, 13, 17....