diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index f99f699988b606db73cf0431befbd7fef08eb083..ca683e07d97fc2d4806b877aec96db28cf7e7658 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 cd1742c954a2aef97c580a6f148b53f2f47712ff..a501c7619bc2038a9bb465e8aa50f4817d72c491 100644 --- a/tests/run/generators.pyx +++ b/tests/run/generators.pyx @@ -295,10 +295,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 ac364234be9559dc8f5a978e906db47f40a40321..57a11d0a9cccf553e310d176a933690a54c0a09c 100644 --- a/tests/run/generators_py.py +++ b/tests/run/generators_py.py @@ -7,10 +7,6 @@ except ImportError: def next(it): return it.next() -if hasattr(__builtins__, 'GeneratorExit'): - GeneratorExit = __builtins__.GeneratorExit -else: # < 2.5 - GeneratorExit = StopIteration def very_simple(): """ @@ -280,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))