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 jdharper
Recipients jdharper
Date 2011-02-18.17:41:04
SpamBayes Score 2.6887141e-08
Marked as misclassified No
Message-id <1298050865.48.0.559427704302.issue11244@psf.upfronthosting.co.za>
In-reply-to
Content
In Python 3.2, a tuple like (1,-2,3) will not be optimized into a constants at compile time.  The tuple is built at run-time.  Earlier versions of Python optimized these tuples at compile time.

Here's an example program.

# test.py
from dis import dis

def x(): return (1,2,3)
def y(): return (1,-2,3)

print ("dis x:")
dis(x)
print()

print("dis y:")
dis(y)

The compiler in 3.2rc3 produces code for function y() that builds the tuple at run-time while the tuple in x() is optimized at compile time.

C:\tmp>c:\python32\python --version
Python 3.2rc3

C:\tmp>c:\python32\python test.py
dis x:
  3           0 LOAD_CONST               4 ((1, 2, 3))
              3 RETURN_VALUE

dis y:
  4           0 LOAD_CONST               1 (1)
              3 LOAD_CONST               4 (-2)
              6 LOAD_CONST               3 (3)
              9 BUILD_TUPLE              3
             12 RETURN_VALUE

However, under 3.1.3, the tuples in both functions are optimized at compile time.

C:\tmp>c:\python31\python test.py
dis x:
  3           0 LOAD_CONST               4 ((1, 2, 3))
              3 RETURN_VALUE

dis y:
  4           0 LOAD_CONST               4 ((1, -2, 3))
              3 RETURN_VALUE

Although the compiled code produced 3.2rc3 is correct, it is much slower than the code generated by 3.1.3.
History
Date User Action Args
2011-02-18 17:41:05jdharpersetrecipients: + jdharper
2011-02-18 17:41:05jdharpersetmessageid: <1298050865.48.0.559427704302.issue11244@psf.upfronthosting.co.za>
2011-02-18 17:41:04jdharperlinkissue11244 messages
2011-02-18 17:41:04jdharpercreate