[Python-checkins] r42772 - in python/trunk/Lib: compiler/transformer.py test/test_compiler.py

guido.van.rossum python-checkins at python.org
Thu Mar 2 05:24:09 CET 2006


Author: guido.van.rossum
Date: Thu Mar  2 05:24:01 2006
New Revision: 42772

Modified:
   python/trunk/Lib/compiler/transformer.py
   python/trunk/Lib/test/test_compiler.py
Log:
Fix failure of test_compiler.py when compiling test_contextlib.py.
The culprit was an expression-less yield -- the first apparently in
the standard library.  I added a unit test for this.
Also removed the hack to force compilation of test_with.py.


Modified: python/trunk/Lib/compiler/transformer.py
==============================================================================
--- python/trunk/Lib/compiler/transformer.py	(original)
+++ python/trunk/Lib/compiler/transformer.py	Thu Mar  2 05:24:01 2006
@@ -408,11 +408,11 @@
         return Discard(expr, lineno=expr.lineno)
 
     def yield_expr(self, nodelist):
-        if len(nodelist)>1:
-            value = nodelist[1]
+        if len(nodelist) > 1:
+            value = self.com_node(nodelist[1])
         else:
             value = Const(None)
-        return Yield(self.com_node(value), lineno=nodelist[0][2])
+        return Yield(value, lineno=nodelist[0][2])
 
     def raise_stmt(self, nodelist):
         # raise: [test [',' test [',' test]]]

Modified: python/trunk/Lib/test/test_compiler.py
==============================================================================
--- python/trunk/Lib/test/test_compiler.py	(original)
+++ python/trunk/Lib/test/test_compiler.py	Thu Mar  2 05:24:01 2006
@@ -20,7 +20,7 @@
             for basename in os.listdir(dir):
                 if not basename.endswith(".py"):
                     continue
-                if not TEST_ALL and random() < 0.98 and basename != "test_with.py":
+                if not TEST_ALL and random() < 0.98:
                     continue
                 path = os.path.join(dir, basename)
                 if test.test_support.verbose:
@@ -43,6 +43,9 @@
     def testNewClassSyntax(self):
         compiler.compile("class foo():pass\n\n","<string>","exec")
 
+    def testYieldExpr(self):
+        compiler.compile("def g(): yield\n\n", "<string>", "exec")
+
     def testLineNo(self):
         # Test that all nodes except Module have a correct lineno attribute.
         filename = __file__


More information about the Python-checkins mailing list