From: Vitja Makarov Date: Sun, 9 Jan 2011 11:23:54 +0000 (+0300) Subject: Support nested yields X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=924f1dad8c8e3cbe2ac87e7d2778ba1a2ad043c4;p=cython.git Support nested yields --- diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index aeb2c65f..af79e7e4 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -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: diff --git a/tests/run/generators.pyx b/tests/run/generators.pyx index ca2bd32b..53047284 100644 --- a/tests/run/generators.pyx +++ b/tests/run/generators.pyx @@ -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))