From e946e51b8c244c667b76c2e1dd839d881fcddca5 Mon Sep 17 00:00:00 2001 From: Vitja Makarov Date: Sun, 17 Apr 2011 19:15:38 +0400 Subject: [PATCH] Fix yield inside lambda --- Cython/Compiler/ParseTreeTransforms.py | 5 ++--- tests/run/generators.pyx | 7 ++++--- tests/run/generators_py.py | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index f99f6999..ca683e07 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -193,9 +193,8 @@ class PostParse(ScopeTrackingTransform): collector = YieldNodeCollector() collector.visitchildren(node.result_expr) if collector.yields or isinstance(node.result_expr, ExprNodes.YieldExprNode): - body = ExprNodes.YieldExprNode( - node.result_expr.pos, arg=node.result_expr) - body = Nodes.ExprStatNode(node.result_expr.pos, expr=body) + body = Nodes.ExprStatNode( + node.result_expr.pos, expr=node.result_expr) else: body = Nodes.ReturnStatNode( node.result_expr.pos, value=node.result_expr) diff --git a/tests/run/generators.pyx b/tests/run/generators.pyx index ef0e8020..97cc72b9 100644 --- a/tests/run/generators.pyx +++ b/tests/run/generators.pyx @@ -291,10 +291,11 @@ def test_inside_lambda(): >>> obj = test_inside_lambda()() >>> next(obj) 1 - >>> obj.send('a') + >>> next(obj) 2 - >>> obj.send('b') - ('a', 'b') + >>> next(obj) + Traceback (most recent call last): + StopIteration """ return lambda:((yield 1), (yield 2)) diff --git a/tests/run/generators_py.py b/tests/run/generators_py.py index 7fe48549..57a11d0a 100644 --- a/tests/run/generators_py.py +++ b/tests/run/generators_py.py @@ -276,10 +276,11 @@ def test_inside_lambda(): >>> obj = test_inside_lambda()() >>> next(obj) 1 - >>> obj.send('a') + >>> next(obj) 2 - >>> obj.send('b') - ('a', 'b') + >>> next(obj) + Traceback (most recent call last): + StopIteration """ return lambda:((yield 1), (yield 2)) -- 2.26.2