[pypy-svn] r55730 - in pypy/dist/pypy/interpreter: astcompiler test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Jun 10 11:08:56 CEST 2008


Author: cfbolz
Date: Tue Jun 10 11:08:54 2008
New Revision: 55730

Modified:
   pypy/dist/pypy/interpreter/astcompiler/pycodegen.py
   pypy/dist/pypy/interpreter/test/test_interpreter.py
Log:
be _completely_ compatible with CPython and start numbering with 1. Write a
test for the behaviour


Modified: pypy/dist/pypy/interpreter/astcompiler/pycodegen.py
==============================================================================
--- pypy/dist/pypy/interpreter/astcompiler/pycodegen.py	(original)
+++ pypy/dist/pypy/interpreter/astcompiler/pycodegen.py	Tue Jun 10 11:08:54 2008
@@ -596,8 +596,8 @@
     def visitListComp(self, node):
         self.set_lineno(node)
         # setup list
-        tmpname = "_[%d]" % self.__list_count
         self.__list_count = self.__list_count + 1
+        tmpname = "_[%d]" % self.__list_count
         self.emitop_int('BUILD_LIST', 0)
         self.emit('DUP_TOP')
         self._implicitNameOp('STORE', tmpname)

Modified: pypy/dist/pypy/interpreter/test/test_interpreter.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_interpreter.py	(original)
+++ pypy/dist/pypy/interpreter/test/test_interpreter.py	Tue Jun 10 11:08:54 2008
@@ -231,6 +231,13 @@
         assert self.codetest(code, 'g', [12, {}]) ==    ()
         assert self.codetest(code, 'g', [12, {3:1}]) == (3,)
 
+    def test_list_comprehension(self):
+        code = '''
+            def f():
+                return [dir() for i in [1]][0]
+        '''
+        assert self.codetest(code, 'f', [])[0] == '_[1]'
+
 
 class TestPyPyInterpreter(TestInterpreter):
     """Runs the previous test with the pypy parser"""



More information about the Pypy-commit mailing list