Issue 1520864: unpack list of singleton tuples not unpacking (original) (raw)
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. :-)
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]