[Python-Dev] Tricky way of of creating a generator via a comprehension expression (original) (raw)

Yury Selivanov yselivanov.ml at gmail.com
Sat Nov 25 17:23:32 EST 2017


On Sat, Nov 25, 2017 at 3:27 PM, Guido van Rossum <guido at python.org> wrote:

On Sat, Nov 25, 2017 at 9:21 AM, Yury Selivanov <yselivanov.ml at gmail.com> wrote:

So we are keeping asynchronous generator expressions as long as they are defined in an 'async def' coroutine? I would be happy to declare that await is out of scope for this thread. It seems that it is always well-defined and sensible what it does in comprehensions and in genexprs. (Although I can't help noticing that PEP 530 does not appear to propose await in generator expressions -- it proposes async for in comprehensions and in genexprs, and await in comprehensions only -- but they appear to be accepted nevertheless.)

Great!

As for PEP 530, after reading this discussion I realized how many things in it are underspecified. I'll be working on PEP 550 successor next week and will also try to update PEP 530 to make it clearer.

So we're back to the original issue, which is that yield inside a comprehension accidentally makes it become a generator rather than a list, set or dict. I believe that this can be fixed. But I don't believe we should fix it. I believe we should ban yield from comprehensions and from genexprs.

+1 from me.

Yury



More information about the Python-Dev mailing list