This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Overly general claim about sequence unpacking in tutorial
Type: Stage:
Components: Documentation Versions: Python 3.0, Python 3.1, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: MLModel, georg.brandl, rhettinger
Priority: normal Keywords:

Created on 2009-01-21 01:54 by MLModel, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg80307 - (view) Author: Mitchell Model (MLModel) Date: 2009-01-21 01:54
The datastructures section of the tutorial states with respect to 
"sequence unpacking" that "there is a small bit of asymmetry here: packing 
multiple values always creates a tuple, and unpacking works for any 
sequence". This is too general, as shown by the definition of assignment 
statement target in the simple_stmts section of the reference shows: 
tuples and lists are the only kinds of sequences that can appear on the 
left-hand side of an assignment statement.
msg80309 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-01-21 02:01
Suggested rewording?
msg80316 - (view) Author: Mitchell Model (MLModel) Date: 2009-01-21 05:20
I've read those paragraphs many times.  Oddly enough when you asked me 
for a rewording and I went back and read them again I found a very 
different interpretation than all the other times.  I've always thought 
of unpacking as being about the variables on the left rather than the 
values on the right. 

Now that I am rethinking this I realize (a) that unpacking is always 
about both sides of the assignment and (b) the wording I criticized is 
actually precise and accurate, if a bit subtle.  What I noticed this 
time is that "the sequence" in the sentence beginning "Sequence 
unpacking" refers to the sequence on the right, not the variables on the 
left, especially since "the variables on the left" are mentioned earlier 
in the sentence.

Part of how I backed into the wrong corner with this is that the left-
hand side of an unpacking can be a list as well as a tuple. I was 
checking to see if any other kinds of sequences could go on the left, 
which of course they can't. That's why I thought "works for any 
sequence" was wrong.  If only a tuple could be on the left I think I 
would have realized what this was saying sooner. It was the fact that 
more than one kind of sequence could go on the left that got be 
sidetracked.

Moreover, the example shows a target list and doesn't even show an 
explicit tuple or a list.  So, it's being fairly informal, as is 
appropriate for a tutorial.  However, with all that sorted out I now see 
a different problem: "multiple assignment is really just a combination 
of tuple packing and sequence unpacking".  If there is an explicit 
tuple, or a list, on the left-hand side then there's no packing 
involved. In fact it's rather strange that one could put something like 
[x,y,z] on the left-hand side of the assignment. I suppose it must get 
converted during compilation to a tuple for multiple assignment -- it's 
not as if a list-valued variable could go there.

Sorry about the long-winded meditation.  Hope the exploration proves 
interesting and or valuable to someone!
msg84939 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-03-31 22:41
I've just removed the paragraph about the asymmetry in r70915.
History
Date User Action Args
2022-04-11 14:56:44adminsetgithub: 49268
2009-03-31 22:41:10georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg84939
2009-01-21 05:20:05MLModelsetmessages: + msg80316
2009-01-21 02:01:16rhettingersetnosy: + rhettinger
messages: + msg80309
2009-01-21 01:54:25MLModelcreate