Message130917
Since the time 'x in set' optimization was added to peephole it has the following bug with set unpacking:
>>> def foo(x,y):
a,b = {x,y}
return a,b
>>> dis(foo)
2 0 LOAD_FAST 0 (x)
3 LOAD_FAST 1 (y)
6 ROT_TWO
7 STORE_FAST 2 (a)
10 STORE_FAST 3 (b)
3 13 LOAD_FAST 2 (a)
16 LOAD_FAST 3 (b)
19 BUILD_TUPLE 2
22 RETURN_VALUE
That is, unpacking of literal set of sizes 2 and 3 is changed to ROT instructions. This, however, changes the semantics, as construction of set would eliminate duplicates.
The difference can be demonstrated like this:
Python 3.1
>>> foo(1,1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in foo
ValueError: need more than 1 value to unpack
Python 3.2
>>> foo(1,1)
(1, 1) |
|
Date |
User |
Action |
Args |
2011-03-14 22:06:04 | eltoder | set | recipients:
+ eltoder |
2011-03-14 22:06:03 | eltoder | set | messageid: <1300140363.98.0.218128326427.issue11510@psf.upfronthosting.co.za> |
2011-03-14 22:06:03 | eltoder | link | issue11510 messages |
2011-03-14 22:06:03 | eltoder | create | |
|