Commit 32a6519a authored by Stefan Behnel's avatar Stefan Behnel

enable support for yield in return expressions

--HG--
extra : transplant_source : %94%87%D7e%B9%82%EF%926%26o%C0%8E%0DcY%C3%E3n%DB
parent d9629b35
......@@ -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):
......
......@@ -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)
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