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

Ivan Levkivskyi levkivskyi at gmail.com
Wed Nov 22 10:10:11 EST 2017


On 22 November 2017 at 15:47, Paul Moore <p.f.moore at gmail.com> wrote:

I generally don't understand "await" in any context, so I deferred judgement on that :-) Based on your comment that they are equally tricky, I'd suggest we prohibit them both ;-)

Less facetiously, comprehensions are defined in the language reference in terms of a source translation to nested loops. That description isn't 100% precise, but nevertheless, if yield/async in a comprehension doesn't behave like that, I'd consider it a bug. So current behaviour (for both yield and await) is a bug, and your proposed semantics for yield is correct.

I think there may be a small misunderstanding here. The situation is different for comprehensions and generator expressions, let me summarize the current state:

After some thinking, both yield and await look quite mind bending in generator expressions, so maybe the right compromise strategy is:

What do you think?

-- Ivan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20171122/0b9967d6/attachment.html>



More information about the Python-Dev mailing list