diff options
-rw-r--r-- | Lib/test/test_generators.py | 10 | ||||
-rw-r--r-- | Misc/NEWS | 2 | ||||
-rw-r--r-- | Python/compile.c | 7 |
3 files changed, 18 insertions, 1 deletions
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index 8f2da7d..9b4e342 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 '<generator object f at ...>' + +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 @@ -56,6 +56,8 @@ Core and Builtins - Issue #4569: Interpreter crash when mutating a memoryview with an item size larger than 1. +- Issue #4748: Lambda generators no longer return a value. + Library ------- diff --git a/Python/compile.c b/Python/compile.c index 36f8c13..e50c75c 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1704,7 +1704,12 @@ compiler_lambda(struct compiler *c, expr_ty e) c->u->u_argcount = asdl_seq_LEN(args->args); c->u->u_kwonlyargcount = asdl_seq_LEN(args->kwonlyargs); 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) |