[Python-checkins] r67954 - in python/trunk: Lib/test/test_generators.py Misc/NEWS Python/compile.c
benjamin.peterson
python-checkins at python.org
Sat Dec 27 19:24:12 CET 2008
Author: benjamin.peterson
Date: Sat Dec 27 19:24:11 2008
New Revision: 67954
Log:
#4748 lambda generators shouldn't return values
Modified:
python/trunk/Lib/test/test_generators.py
python/trunk/Misc/NEWS
python/trunk/Python/compile.c
Modified: python/trunk/Lib/test/test_generators.py
==============================================================================
--- python/trunk/Lib/test/test_generators.py (original)
+++ python/trunk/Lib/test/test_generators.py Sat Dec 27 19:24:11 2008
@@ -928,6 +928,16 @@
'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
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Sat Dec 27 19:24:11 2008
@@ -83,6 +83,8 @@
- 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
-------
Modified: python/trunk/Python/compile.c
==============================================================================
--- python/trunk/Python/compile.c (original)
+++ python/trunk/Python/compile.c Sat Dec 27 19:24:11 2008
@@ -1534,7 +1534,12 @@
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)
More information about the Python-checkins
mailing list