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

Martin Panter report at bugs.python.org
Tue Jul 7 01:59:05 CEST 2015


Martin Panter added the comment:

Yes I think it is expected and documented that the leftovers are turned into a list. See <https://docs.python.org/3.5/reference/simple_stmts.html#index-6>. I originally had similar confusion, expectating the starred target to become a tuple, because people often use tuple-like syntax, but:

>>> generator_expression = (2**i for i in range(4))
>>> (one, *a_list, eight) = generator_expression
>>> a_list  # Not a tuple!
[2, 4]

One thing in the section I linked above that should also be fixed is that the assigned object may be any iterable, not just a sequence.

About changing the tutorial, just be careful you don’t add unnecessary complication too early. The original * and ** syntax for function parameters is not mentioned until <https://docs.python.org/3.5/tutorial/controlflow.html#more-on-defining-functions>. Later, argument unpacking: <https://docs.python.org/3.5/tutorial/controlflow.html#unpacking-argument-lists>. Assignment unpacking doesn’t seem to mentioned at all (not that I am saying it should be). It might be higher priority to update the main reference documentation first.

----------
title: document PEP 448 -> document PEP 448: unpacking generalization

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24136>
_______________________________________


More information about the docs mailing list