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.

Author eltoder
Recipients eltoder
Date 2011-03-14.22:06:03
SpamBayes Score 7.203682e-11
Marked as misclassified No
Message-id <1300140363.98.0.218128326427.issue11510@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2011-03-14 22:06:04eltodersetrecipients: + eltoder
2011-03-14 22:06:03eltodersetmessageid: <1300140363.98.0.218128326427.issue11510@psf.upfronthosting.co.za>
2011-03-14 22:06:03eltoderlinkissue11510 messages
2011-03-14 22:06:03eltodercreate