summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-09-22 18:44:21 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-09-22 18:44:21 (GMT)
commit2c31a058eb719da8908ea9d9c2f1b748ecc7a4ca (patch)
tree8795a38ea15df04a9427f00c8ae826108bc7cc1e /Lib
parent0318a939dd0881b26b2ec7239cedd2faa58a4412 (diff)
downloadcpython-2c31a058eb719da8908ea9d9c2f1b748ecc7a4ca.zip
cpython-2c31a058eb719da8908ea9d9c2f1b748ecc7a4ca.tar.gz
cpython-2c31a058eb719da8908ea9d9c2f1b748ecc7a4ca.tar.bz2
SF patch #1031667: Fold tuples of constants into a single constant
Example: >>> import dis >>> dis.dis(compile('1,2,3', '', 'eval')) 0 0 LOAD_CONST 3 ((1, 2, 3)) 3 RETURN_VALUE
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_peepholer.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py
index 33eb0f5..913f805 100644
--- a/Lib/test/test_peepholer.py
+++ b/Lib/test/test_peepholer.py
@@ -64,15 +64,25 @@ class TestTranforms(unittest.TestCase):
def test_pack_unpack(self):
for line, elem in (
- ('a, = 1,', 'LOAD_CONST',),
- ('a, b = 1, 2', 'ROT_TWO',),
- ('a, b, c = 1, 2, 3', 'ROT_THREE',),
+ ('a, = a,', 'LOAD_CONST',),
+ ('a, b = a, b', 'ROT_TWO',),
+ ('a, b, c = a, b, c', 'ROT_THREE',),
):
asm = dis_single(line)
self.assert_(elem in asm)
self.assert_('BUILD_TUPLE' not in asm)
self.assert_('UNPACK_TUPLE' not in asm)
+ def test_folding_of_tuples_of_constants(self):
+ for line, elem in (
+ ('a = 1,2,3', '((1, 2, 3))',),
+ ('("a","b","c")', "(('a', 'b', 'c'))",),
+ ('a,b,c = 1,2,3', '((1, 2, 3))',),
+ ):
+ asm = dis_single(line)
+ self.assert_(elem in asm)
+ self.assert_('BUILD_TUPLE' not in asm)
+
def test_elim_extra_return(self):
# RETURN LOAD_CONST None RETURN --> RETURN
def f(x):