From 542198a9a796be5427f3f436d726dfd24df3abcd Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 5 Jul 2013 20:00:49 +0200 Subject: [PATCH] enable support for yield in return expressions --HG-- extra : rebase_source : 562b717b9c1e078b3f83e3febc8addc1a29d85fe --- Cython/Compiler/ParseTreeTransforms.py | 4 +++- tests/run/yield_from_pep380.pyx | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index 66dff9b..4b2fe01 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -2096,13 +2096,14 @@ class YieldNodeCollector(TreeVisitor): self.has_return_value = False def visit_Node(self, node): - return self.visitchildren(node) + self.visitchildren(node) def visit_YieldExprNode(self, node): self.yields.append(node) self.visitchildren(node) def visit_ReturnStatNode(self, node): + self.visitchildren(node) if node.value: self.has_return_value = True self.returns.append(node) @@ -2119,6 +2120,7 @@ class YieldNodeCollector(TreeVisitor): def visit_GeneratorExpressionNode(self, node): pass + class MarkClosureVisitor(CythonTransform): def visit_ModuleNode(self, node): diff --git a/tests/run/yield_from_pep380.pyx b/tests/run/yield_from_pep380.pyx index 676307c..b8ed3aa 100644 --- a/tests/run/yield_from_pep380.pyx +++ b/tests/run/yield_from_pep380.pyx @@ -1004,3 +1004,17 @@ def test_delegating_generators_claim_to_be_running_close(): ret = next(g1) g1.close() return ret + + +def yield_in_return(x): + """ + >>> x = yield_in_return(range(3)) + >>> while True: + ... try: + ... print(next(x)) + ... except StopIteration as exc: + ... print(exc.value) + ... break + + """ + return (yield from x) -- 2.7.4