Skip to content

Commit 9c688a9

Browse files
author
benjamin.peterson
committed
Merged revisions 67954 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r67954 | benjamin.peterson | 2008-12-27 12:24:11 -0600 (Sat, 27 Dec 2008) | 1 line #4748 lambda generators shouldn't return values ........ git-svn-id: http://svn.python.org/projects/python/branches/py3k@67959 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 1f157cc commit 9c688a9

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

Lib/test/test_generators.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,16 @@
928928
'f'
929929
>>> repr(g) # doctest: +ELLIPSIS
930930
'<generator object f at ...>'
931+
932+
Lambdas shouldn't have their usual return behavior.
933+
934+
>>> x = lambda: (yield 1)
935+
>>> list(x())
936+
[1]
937+
938+
>>> x = lambda: ((yield 1), (yield 2))
939+
>>> list(x())
940+
[1, 2]
931941
"""
932942

933943
# conjoin is a simple backtracking generator, named in honor of Icon's

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Core and Builtins
5656
- Issue #4569: Interpreter crash when mutating a memoryview with an item size
5757
larger than 1.
5858

59+
- Issue #4748: Lambda generators no longer return a value.
60+
5961
Library
6062
-------
6163

Python/compile.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,12 @@ compiler_lambda(struct compiler *c, expr_ty e)
17041704
c->u->u_argcount = asdl_seq_LEN(args->args);
17051705
c->u->u_kwonlyargcount = asdl_seq_LEN(args->kwonlyargs);
17061706
VISIT_IN_SCOPE(c, expr, e->v.Lambda.body);
1707-
ADDOP_IN_SCOPE(c, RETURN_VALUE);
1707+
if (c->u->u_ste->ste_generator) {
1708+
ADDOP_IN_SCOPE(c, POP_TOP);
1709+
}
1710+
else {
1711+
ADDOP_IN_SCOPE(c, RETURN_VALUE);
1712+
}
17081713
co = assemble(c, 1);
17091714
compiler_exit_scope(c);
17101715
if (co == NULL)

0 commit comments

Comments
 (0)