This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Inyeol.Lee
Recipients Inyeol.Lee
Date 2010-11-26.19:21:17
SpamBayes Score 4.6287798e-07
Marked as misclassified No
Message-id <1290799279.15.0.89740732651.issue10544@psf.upfronthosting.co.za>
In-reply-to
Content
Simple coroutine with for loop works:

>>> def pack_a():
        while True:
            L = []
            for i in range(2):
                L.append((yield))
            print(L)

>>> pa = pack_a()
>>> next(pa)
>>> pa.send(1)
>>> pa.send(2)
[1, 2]
>>>

If using list comprehension (generator expression), it fails:

>>> def pack_b():
        while True:
            L = [(yield) for i in range(2)]
            print(L)

>>> 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.
History
Date User Action Args
2010-11-26 19:21:19Inyeol.Leesetrecipients: + Inyeol.Lee
2010-11-26 19:21:19Inyeol.Leesetmessageid: <1290799279.15.0.89740732651.issue10544@psf.upfronthosting.co.za>
2010-11-26 19:21:17Inyeol.Leelinkissue10544 messages
2010-11-26 19:21:17Inyeol.Leecreate