[New-bugs-announce] [issue10544] yield expression inside generator expression does nothing
report at bugs.python.org
Fri Nov 26 20:21:19 CET 2010
New submission from Inyeol Lee <inyeol.lee at gmail.com>:
Simple coroutine with for loop works:
>>> def pack_a():
L = 
for i in range(2):
>>> pa = pack_a()
If using list comprehension (generator expression), it fails:
>>> def pack_b():
L = [(yield) for i in range(2)]
>>> pb = pack_b()
<endless loop here>
I understand what's going on here - generator expression is converted to nested function and there's no way to either stop the execution inside nested function (since it's not started yet!) or send() a value to its yield expression. Still I think this behavior is a bug and needs fixed.
- best fix would make it behave the same as for loop.
- if it's not fixable, yield expression inside genexp should not be allowed.
components: Interpreter Core
title: yield expression inside generator expression does nothing
versions: Python 3.1
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce