Index: Python/peephole.c =================================================================== --- Python/peephole.c (revision 61948) +++ Python/peephole.c (working copy) @@ -294,6 +294,8 @@ int cumlc=0, lastlc=0; /* Count runs of consecutive LOAD_CONSTs */ unsigned int *blocks = NULL; char *name; + int *constsmap = NULL; + int constscount; /* Bail out if an exception is set */ if (PyErr_Occurred()) @@ -580,8 +582,8 @@ lineno[i] =((unsigned char)(new_line - last_line)); last_line = new_line; } - - /* Remove NOPs and fixup jump targets */ + + /* Remove NOPs and fixup jump targets and consts indices */ for (i=0, h=0 ; i') +consts: ('',) >>> dump(f(4).func_code) name: g @@ -26,7 +26,7 @@ freevars: ('x',) nlocals: 1 flags: 19 -consts: ('None',) +consts: () >>> def h(x, y): ... a = x + y @@ -43,7 +43,7 @@ freevars: () nlocals: 5 flags: 67 -consts: ('None',) +consts: () >>> def attrs(obj): ... print obj.attr1 Index: Lib/test/test_dis.py =================================================================== --- Lib/test/test_dis.py (revision 61948) +++ Lib/test/test_dis.py (working copy) @@ -16,7 +16,7 @@ 3 PRINT_ITEM 4 PRINT_NEWLINE - %-4d 5 LOAD_CONST 1 (1) + %-4d 5 LOAD_CONST 0 (1) 8 RETURN_VALUE """%(_f.func_code.co_firstlineno + 1, _f.func_code.co_firstlineno + 2) Index: Lib/test/test_peepholer.py =================================================================== --- Lib/test/test_peepholer.py (revision 61948) +++ Lib/test/test_peepholer.py (working copy) @@ -202,7 +202,11 @@ self.assertEqual(asm.split().count('JUMP_ABSOLUTE'), 1) self.assertEqual(asm.split().count('RETURN_VALUE'), 2) + def test_elim_unused_consts(self): + f = lambda: 42 + 42 + self.assertFalse(42 in f.__code__.co_consts) + def test_main(verbose=None): import sys from test import test_support