[ python-Bugs-1031667 ] Fold tuples of constants into a single constant

SourceForge.net noreply at sourceforge.net
Tue Sep 21 21:08:35 CEST 2004


Bugs item #1031667, was opened at 2004-09-21 06:23
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1031667&group_id=5470

Category: Python Interpreter Core
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Raymond Hettinger (rhettinger)
Assigned to: Nobody/Anonymous (nobody)
Summary: Fold tuples of constants into a single constant

Initial Comment:
Folds tuples of constants into a single constant. 
Results in beautiful, fast bytecode:


>>> from dis import dis
>>> def f():
	for x in ('a', 'b', 'c'):
	    if x in (1, 2):
		return False
	return True

>>> dis(f)
  2           0 SETUP_LOOP              35 (to 38)
              3 LOAD_CONST               6 (('a', 'b',
'c'))
              6 GET_ITER            
        >>    7 FOR_ITER                27 (to 37)
             10 STORE_FAST               0 (x)

  3          13 LOAD_FAST                0 (x)
             16 LOAD_CONST               7 ((1, 2))
             19 COMPARE_OP               6 (in)
             22 JUMP_IF_FALSE            8 (to 33)
             25 POP_TOP             

  4          26 LOAD_GLOBAL              1 (False)
             29 RETURN_VALUE        
             30 JUMP_ABSOLUTE            7
        >>   33 POP_TOP             
             34 JUMP_ABSOLUTE            7
        >>   37 POP_BLOCK           

  5     >>   38 LOAD_GLOBAL              2 (True)
             41 RETURN_VALUE

----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2004-09-21 21:08

Message:
Logged In: YES 
user_id=21627

There is a change in semantics, of course: the program

def f(): return 1,2
print f() is f()

used to print False, now prints True.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1031667&group_id=5470


More information about the Python-bugs-list mailing list