Commit 542198a9 authored by Stefan Behnel's avatar Stefan Behnel

enable support for yield in return expressions

--HG--
extra : rebase_source : 562b717b9c1e078b3f83e3febc8addc1a29d85fe
parent 31215ed8
...@@ -2096,13 +2096,14 @@ class YieldNodeCollector(TreeVisitor): ...@@ -2096,13 +2096,14 @@ class YieldNodeCollector(TreeVisitor):
self.has_return_value = False self.has_return_value = False
def visit_Node(self, node): def visit_Node(self, node):
return self.visitchildren(node) self.visitchildren(node)
def visit_YieldExprNode(self, node): def visit_YieldExprNode(self, node):
self.yields.append(node) self.yields.append(node)
self.visitchildren(node) self.visitchildren(node)
def visit_ReturnStatNode(self, node): def visit_ReturnStatNode(self, node):
self.visitchildren(node)
if node.value: if node.value:
self.has_return_value = True self.has_return_value = True
self.returns.append(node) self.returns.append(node)
...@@ -2119,6 +2120,7 @@ class YieldNodeCollector(TreeVisitor): ...@@ -2119,6 +2120,7 @@ class YieldNodeCollector(TreeVisitor):
def visit_GeneratorExpressionNode(self, node): def visit_GeneratorExpressionNode(self, node):
pass pass
class MarkClosureVisitor(CythonTransform): class MarkClosureVisitor(CythonTransform):
def visit_ModuleNode(self, node): def visit_ModuleNode(self, node):
......
...@@ -1004,3 +1004,17 @@ def test_delegating_generators_claim_to_be_running_close(): ...@@ -1004,3 +1004,17 @@ def test_delegating_generators_claim_to_be_running_close():
ret = next(g1) ret = next(g1)
g1.close() g1.close()
return ret 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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment