[New-bugs-announce] [issue11510] Peephole breaks set unpacking

Eugene Toder report at bugs.python.org
Mon Mar 14 23:06:03 CET 2011


New submission from Eugene Toder <eltoder at gmail.com>:

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)

----------
components: Interpreter Core
messages: 130917
nosy: eltoder
priority: normal
severity: normal
status: open
title: Peephole breaks set unpacking
type: compile error
versions: Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11510>
_______________________________________


More information about the New-bugs-announce mailing list