[pypy-commit] pypy py3k: apply workarounds from 2.7

pjenvey noreply at buildbot.pypy.org
Sat Feb 23 23:20:50 CET 2013


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r61710:86ae6e1c04b9
Date: 2013-02-23 14:18 -0800
http://bitbucket.org/pypy/pypy/changeset/86ae6e1c04b9/

Log:	apply workarounds from 2.7

diff --git a/lib-python/3.2/test/test_peepholer.py b/lib-python/3.2/test/test_peepholer.py
--- a/lib-python/3.2/test/test_peepholer.py
+++ b/lib-python/3.2/test/test_peepholer.py
@@ -3,6 +3,7 @@
 import sys
 from io import StringIO
 import unittest
+from test.support import check_impl_detail
 
 def disassemble(func):
     f = StringIO()
@@ -43,14 +44,14 @@
     def test_global_as_constant(self):
         # LOAD_GLOBAL None/True/False  -->  LOAD_CONST None/True/False
         def f(x):
-            None
+            y = None
             None
             return x
         def g(x):
-            True
+            y = True
             return x
         def h(x):
-            False
+            y = False
             return x
         for func, name in ((f, 'None'), (g, 'True'), (h, 'False')):
             asm = disassemble(func)
@@ -77,10 +78,13 @@
             self.assertIn(elem, asm)
 
     def test_pack_unpack(self):
+        # On PyPy, "a, b = ..." is even more optimized, by removing
+        # the ROT_TWO.  But the ROT_TWO is not removed if assigning
+        # to more complex expressions, so check that.
         for line, elem in (
             ('a, = a,', 'LOAD_CONST',),
-            ('a, b = a, b', 'ROT_TWO',),
-            ('a, b, c = a, b, c', 'ROT_THREE',),
+            ('a[1], b = a, b', 'ROT_TWO',),
+            ('a, b[2], c = a, b, c', 'ROT_THREE',),
             ):
             asm = dis_single(line)
             self.assertIn(elem, asm)
@@ -88,6 +92,8 @@
             self.assertNotIn('UNPACK_TUPLE', asm)
 
     def test_folding_of_tuples_of_constants(self):
+        # On CPython, "a,b,c=1,2,3" turns into "a,b,c=<constant (1,2,3)>"
+        # but on PyPy, it turns into "a=1;b=2;c=3".
         for line, elem in (
             ('a = 1,2,3', '((1, 2, 3))'),
             ('("a","b","c")', "(('a', 'b', 'c'))"),
@@ -96,7 +102,8 @@
             ('((1, 2), 3, 4)', '(((1, 2), 3, 4))'),
             ):
             asm = dis_single(line)
-            self.assertIn(elem, asm)
+            self.assert_(elem in asm or (
+                line == 'a,b,c = 1,2,3' and 'UNPACK_TUPLE' not in asm))
             self.assertNotIn('BUILD_TUPLE', asm)
 
         # Bug 1053819:  Tuple of constants misidentified when presented with:
@@ -196,13 +203,14 @@
         self.assertIn('(1000)', asm)
 
     def test_binary_subscr_on_unicode(self):
-        # valid code get optimized
-        asm = dis_single('"foo"[0]')
-        self.assertIn("('f')", asm)
-        self.assertNotIn('BINARY_SUBSCR', asm)
-        asm = dis_single('"\u0061\uffff"[1]')
-        self.assertIn("('\\uffff')", asm)
-        self.assertNotIn('BINARY_SUBSCR', asm)
+        if check_impl_detail(pypy=False):
+            # valid code get optimized
+            asm = dis_single('"foo"[0]')
+            self.assertIn("('f')", asm)
+            self.assertNotIn('BINARY_SUBSCR', asm)
+            asm = dis_single('"\u0061\uffff"[1]')
+            self.assertIn("('\\uffff')", asm)
+            self.assertNotIn('BINARY_SUBSCR', asm)
 
         # invalid code doesn't get optimized
         # out of range


More information about the pypy-commit mailing list