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: unpack list of singleton tuples not unpacking
Type: Stage:
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: nnorwitz Nosy List: atuining, georg.brandl, nnorwitz, rhettinger, sadrejeb
Priority: critical Keywords:

Created on 2006-07-11 23:21 by atuining, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
lc-tuple-fix.diff georg.brandl, 2006-09-04 10:05
Messages (6)
msg29136 - (view) Author: Anthony Tuininga (atuining) * Date: 2006-07-11 23:21
The following code works differently in Python 2.5 than
Python 2.4:

x = [(1,), (2,), (3,)]
for y, in x:
    print y

In Python 2.4, this code produces the following:
1
2
3

In Python 2.5, this code produces the following:
(1,)
(2,)
(3,)

Interestingly enough the following code:

x = (1,)
y, = x
print y

produces the output
1

in both Python 2.4 and Python 2.5. I'm thinking this is
not intentional. :-)
msg29137 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2006-07-12 02:38
Logged In: YES 
user_id=80475

Ouch.  This is bad.  The disassembly shows that the compiler
 isn't generating the unpack_sequence opcode.
msg29138 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-07-12 05:26
Logged In: YES 
user_id=33168

Awww come on, can't we change the language just to make your
life difficult? ;-)

Thanks a lot for catching this!

Committed revision 50597.
msg29139 - (view) Author: Sadruddin Rejeb (sadrejeb) Date: 2006-09-04 09:08
Logged In: YES 
user_id=26911

I have the impression that the bug has only been partially
solved, i.e. in 2.5c1, singleton tuples don't get unfoled in
list comprehensions.

Python 2.5c1 (r25c1:51305, Sep  4 2006, 10:15:09)
[GCC 4.1.1 20060525 (Red Hat 4.1.1-1)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> l = [(1,), (2,)]
>>> print [x for x, in l]
[(1,), (2,)]

Same example in Python 2.4.3:

Python 2.4.3 (#1, Jul 25 2006, 11:53:03)
[GCC 4.1.1 20060525 (Red Hat 4.1.1-1)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> l = [(1,), (2,)]
>>> print [x for x, in l]
[1, 2]
msg29140 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-09-04 10:05
Logged In: YES 
user_id=849994

You're right. Attached patch fixes this.
msg29141 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-09-05 04:01
Logged In: YES 
user_id=33168

Thanks for spotting this.  Let us know if you find any more
bugs.

Well, I'm glad Georg and I came up with the same basic patch
(thanks Georg!).  I had worked it up prior to seeing his
version here.  It's also the same fix for the for loops.

Committed revision 51729. (2.6)
Committed revision 51730. (2.5)
History
Date User Action Args
2022-04-11 14:56:18adminsetgithub: 43651
2006-07-11 23:21:13atuiningcreate