From 924f1dad8c8e3cbe2ac87e7d2778ba1a2ad043c4 Mon Sep 17 00:00:00 2001 From: Vitja Makarov Date: Sun, 9 Jan 2011 14:23:54 +0300 Subject: [PATCH] Support nested yields --- Cython/Compiler/ParseTreeTransforms.py | 1 + tests/run/generators.pyx | 15 +++++++++++++++ 2 files changed, 16 insertions(+) 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)) -- 2.26.2