From: Benjamin Peterson Date: Sat, 27 Dec 2008 18:24:11 +0000 (+0000) Subject: #4748 lambda generators shouldn't return values X-Git-Tag: v2.7a1~2489 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8d5934b25d7c3e636444428dc715316a08b8c94e;p=python #4748 lambda generators shouldn't return values --- diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index 3702abc91a..b7c3fdcbe5 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -928,6 +928,16 @@ Test the __name__ attribute and the repr() 'f' >>> repr(g) # doctest: +ELLIPSIS '' + +Lambdas shouldn't have their usual return behavior. + +>>> x = lambda: (yield 1) +>>> list(x()) +[1] + +>>> x = lambda: ((yield 1), (yield 2)) +>>> list(x()) +[1, 2] """ # conjoin is a simple backtracking generator, named in honor of Icon's diff --git a/Misc/NEWS b/Misc/NEWS index 4a15054eb5..64ff4062c8 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -83,6 +83,8 @@ Core and Builtins - Issue #4509: Various issues surrounding resize of bytearray objects to which there are buffer exports. +- Issue #4748: Lambda generators no longer return a value. + Library ------- diff --git a/Python/compile.c b/Python/compile.c index 756a903340..8f0fd8d043 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1534,7 +1534,12 @@ compiler_lambda(struct compiler *c, expr_ty e) c->u->u_argcount = asdl_seq_LEN(args->args); VISIT_IN_SCOPE(c, expr, e->v.Lambda.body); - ADDOP_IN_SCOPE(c, RETURN_VALUE); + if (c->u->u_ste->ste_generator) { + ADDOP_IN_SCOPE(c, POP_TOP); + } + else { + ADDOP_IN_SCOPE(c, RETURN_VALUE); + } co = assemble(c, 1); compiler_exit_scope(c); if (co == NULL)