]> granicus.if.org Git - python/commitdiff
#4748 lambda generators shouldn't return values
authorBenjamin Peterson <benjamin@python.org>
Sat, 27 Dec 2008 18:24:11 +0000 (18:24 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 27 Dec 2008 18:24:11 +0000 (18:24 +0000)
Lib/test/test_generators.py
Misc/NEWS
Python/compile.c

index 3702abc91afdec2cd6d8957d705bb85231536648..b7c3fdcbe5473986dd631a9bb4b9c085633588be 100644 (file)
@@ -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
index 4a15054eb55ac0347ec6a8491d01776a1e90fe7b..64ff4062c86a9eb19424e6e724fb1e8467f48caa 100644 (file)
--- 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
 -------
 
index 756a903340827f26a10abf0df29224a279159bea..8f0fd8d0433fe0e0a0994f69cf574cc618a90412 100644 (file)
@@ -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)