[docs] [issue24136] document PEP 448: unpacking generalization

Martin Panter report at bugs.python.org
Sat Jun 11 01:25:18 EDT 2016

Martin Panter added the comment:

Here is a new patch that also updates the documentation for list etc displays as well as function calls. Let me know what you think.

The 3.5 What’s New notes were written separately; Neil’s patch was never applied. But I have rescued his update for functools.partial() in my new patch.

While experimenting with the current behaviour, I found some surprising inconsistencies. The following syntaxes are allowed:

>>> x, *y
>>> a = x, *y
>>> f"{x, *y}"  # New in 3.6
>>> async def f(): await x, *y

But the following all produce “SyntaxError: invalid syntax”:

>>> a += x, *y
>>> eval("x, *y")
>>> def f(): return x, *y
>>> def f(): yield x, *y
>>> for i in x, *y: ...

Also, the expressions allowed for unpacking in general are more limited than in function calls:

>>> f(x, *y == z)  # Allowed
>>> (x, *y == z)
SyntaxError: invalid syntax

Added file: http://bugs.python.org/file43339/unpacking-doc.patch

Python tracker <report at bugs.python.org>

More information about the docs mailing list