[pypy-svn] r76269 - in pypy/trunk/pypy/interpreter/astcompiler: . test

agaynor at codespeak.net agaynor at codespeak.net
Sat Jul 17 04:10:39 CEST 2010


Author: agaynor
Date: Sat Jul 17 04:10:37 2010
New Revision: 76269

Modified:
   pypy/trunk/pypy/interpreter/astcompiler/ast.py
   pypy/trunk/pypy/interpreter/astcompiler/test/test_compiler.py
Log:
Ensure that all elements of a list comprehension are optimized by the AST optimizer.  Previously  wasn't turning None into a LOAD_CONST.

Modified: pypy/trunk/pypy/interpreter/astcompiler/ast.py
==============================================================================
--- pypy/trunk/pypy/interpreter/astcompiler/ast.py	(original)
+++ pypy/trunk/pypy/interpreter/astcompiler/ast.py	Sat Jul 17 04:10:37 2010
@@ -1398,6 +1398,7 @@
 
     def mutate_over(self, visitor):
         self.elt = self.elt.mutate_over(visitor)
+        visitor._mutate_sequence(self.generators)
         return visitor.visit_ListComp(self)
 
     def sync_app_attrs(self, space):
@@ -2295,6 +2296,13 @@
 
     def walkabout(self, visitor):
         visitor.visit_comprehension(self)
+    
+    def mutate_over(self, visitor):
+        self.target = self.target.mutate_over(visitor)
+        self.iter = self.iter.mutate_over(visitor)
+        if self.ifs:
+            visitor._mutate_sequence(self.ifs)
+        return visitor.visit_comprehension(self)
 
     def sync_app_attrs(self, space):
         if (self.initialization_state & ~0) ^ 7:

Modified: pypy/trunk/pypy/interpreter/astcompiler/test/test_compiler.py
==============================================================================
--- pypy/trunk/pypy/interpreter/astcompiler/test/test_compiler.py	(original)
+++ pypy/trunk/pypy/interpreter/astcompiler/test/test_compiler.py	Sat Jul 17 04:10:37 2010
@@ -216,6 +216,9 @@
                "l",
                [(2, 0), (4, 0), (5, 3), (6, 0),
                 (7, 3), (8, 0), (8, 6), (9, 3)])
+    
+    def test_list_comprehensions(self):
+        yield (self.st, "l = [x for x in range(10) if None]", "l", [])
 
     def test_genexprs(self):
         yield (self.st,



More information about the Pypy-commit mailing list