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 pfalcon
Recipients alex, belopolsky, benjamin.peterson, dmalcolm, jhylton, nnorwitz, pfalcon, rhettinger, sdahlbac, terry.reedy, thomaslee, titanstar
Date 2014-01-01.04:51:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1388551909.49.0.326252300697.issue1346238@psf.upfronthosting.co.za>
In-reply-to
Content
8 years after the original patch, there's still no trivial constant folding in bytecode generated (because peephole of course is not a real optimizer to consistently catch all cases):

$ cat const.py 
FOO = 1
BAR = FOO + 2 + 4

$ python --version
Python 2.7.3

$ python -OO -m dis const.py
  1           0 LOAD_CONST               0 (1)
              3 STORE_NAME               0 (FOO)

  2           6 LOAD_NAME                0 (FOO)
              9 LOAD_CONST               1 (2)
             12 BINARY_ADD          
             13 LOAD_CONST               2 (4)
             16 BINARY_ADD          
             17 STORE_NAME               1 (BAR)
             20 LOAD_CONST               3 (None)
             23 RETURN_VALUE        

$ python3.3 --version
Python 3.3.3

$ python3.3 -OO -m dis const.py
  1           0 LOAD_CONST               0 (1) 
              3 STORE_NAME               0 (FOO) 

  2           6 LOAD_NAME                0 (FOO) 
              9 LOAD_CONST               1 (2) 
             12 BINARY_ADD           
             13 LOAD_CONST               2 (4) 
             16 BINARY_ADD           
             17 STORE_NAME               1 (BAR) 
             20 LOAD_CONST               3 (None) 
             23 RETURN_VALUE
History
Date User Action Args
2014-01-01 04:51:49pfalconsetrecipients: + pfalcon, jhylton, nnorwitz, rhettinger, terry.reedy, belopolsky, sdahlbac, titanstar, thomaslee, benjamin.peterson, alex, dmalcolm
2014-01-01 04:51:49pfalconsetmessageid: <1388551909.49.0.326252300697.issue1346238@psf.upfronthosting.co.za>
2014-01-01 04:51:49pfalconlinkissue1346238 messages
2014-01-01 04:51:48pfalconcreate