Support nested yields
authorVitja Makarov <vitja.makarov@gmail.com>
Sun, 9 Jan 2011 11:23:54 +0000 (14:23 +0300)
committerVitja Makarov <vitja.makarov@gmail.com>
Sun, 9 Jan 2011 11:23:54 +0000 (14:23 +0300)
Cython/Compiler/ParseTreeTransforms.py
tests/run/generators.pyx

index aeb2c65ffb14377dfc9d66d2d9efc30fe15f8544..af79e7e4a5dac84ae3ca59eec0a878352fef1c65 100644 (file)
@@ -1332,6 +1332,7 @@ class YieldNodeCollector(TreeVisitor):
         if self.has_return_value:
             error(node.pos, "'yield' outside function")
         self.yields.append(node)
+        self.visitchildren(node)
 
     def visit_ReturnStatNode(self, node):
         if node.value:
index ca2bd32b8d25709cd433d251db0981a58996b6af..53047284e591cc3602969699da3d867938b7d7a8 100644 (file)
@@ -272,3 +272,18 @@ def test_copied_yield(foo):
     """
     with foo:
         yield 1
+
+def test_nested_yield():
+    """
+    >>> obj = test_nested_yield()
+    >>> next(obj)
+    1
+    >>> obj.send(2)
+    2
+    >>> obj.send(3)
+    3
+    >>> obj.send(4)
+    Traceback (most recent call last):
+    StopIteration
+    """
+    yield (yield (yield 1))