msg78291 - (view) |
Author: Georg Brandl (georg.brandl) *  |
Date: 2008-12-26 09:57 |
With lambda, the ban on "return x" in generators can be evaded: >>> x = lambda: ((yield 1), (yield 2)) >>> list(x()) [1, 2, (None, None)] >>> dis.dis(x) 1 0 LOAD_CONST 0 (1) 3 YIELD_VALUE 4 LOAD_CONST 1 (2) 7 YIELD_VALUE 8 BUILD_TUPLE 2 11 RETURN_VALUE |
|
|
msg78332 - (view) |
Author: Benjamin Peterson (benjamin.peterson) *  |
Date: 2008-12-27 02:02 |
Attaching patch? BTW, how did you find this bug? :) |
|
|
msg78370 - (view) |
Author: Georg Brandl (georg.brandl) *  |
Date: 2008-12-27 17:41 |
I didn't find it, but someone from the German Python webforum. :) Hmm, I wonder why lambda: (yield 1) alone doesn't give [1, None]. (That should also go into the test case.) Anyway, perhaps yield in lambdas should be forbidden. |
|
|
msg78373 - (view) |
Author: Benjamin Peterson (benjamin.peterson) *  |
Date: 2008-12-27 18:07 |
On Sat, Dec 27, 2008 at 11:41 AM, Georg Brandl <report@bugs.python.org> wrote: > > Georg Brandl <georg@python.org> added the comment: > > I didn't find it, but someone from the German Python webforum. :) > > Hmm, I wonder why lambda: (yield 1) alone doesn't give [1, None]. (That > should also go into the test case.) Actually, I don't think the return value should even make it's way to the list. Generator lambdas shouldn't have any return value IMO. > > Anyway, perhaps yield in lambdas should be forbidden. Probably too late now for 2.x and 3.x. |
|
|
msg78374 - (view) |
Author: Georg Brandl (georg.brandl) *  |
Date: 2008-12-27 18:15 |
>> Hmm, I wonder why lambda: (yield 1) alone doesn't give [1, None]. (That >> should also go into the test case.) > > Actually, I don't think the return value should even make it's way to > the list. Generator lambdas shouldn't have any return value IMO. Yes, I think so too. I just wondered at the seemingly inconsistent behavior right now. >> Anyway, perhaps yield in lambdas should be forbidden. > > Probably too late now for 2.x and 3.x. Right. I'd say go for applying the patch. |
|
|
msg78377 - (view) |
Author: Benjamin Peterson (benjamin.peterson) *  |
Date: 2008-12-27 18:24 |
Fixed in r67954. |
|
|