[Python-Dev] Tricky way of of creating a generator via a comprehension expression (original) (raw)
Guido van Rossum guido at python.org
Fri Nov 24 22:30:56 EST 2017
- Previous message (by thread): [Python-Dev] Tricky way of of creating a generator via a comprehension expression
- Next message (by thread): [Python-Dev] Tricky way of of creating a generator via a comprehension expression
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, Nov 24, 2017 at 4:22 PM, Guido van Rossum <guido at python.org> wrote:
The more I hear about this topic, the more I think that
await
,yield
andyield from
should all be banned from occurring in all comprehensions and generator expressions. That's not much different from disallowingreturn
orbreak
.From the responses it seems that I tried to simplify things too far. Let's say that
await
in comprehensions is fine, as long as that comprehension is contained in anasync def
. While we could saveyield [from]
in comprehensions, I still see it as mostly a source of confusion, and the fact that the presence ofyield [from]
implicitly makes the surroundingdef
a generator makes things worse. It just requires too many mental contortions to figure out what it does.
I still propose to rule out all of the above from generator expressions, because those can escape from the surrounding scope.
-- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20171124/144cd334/attachment.html>
- Previous message (by thread): [Python-Dev] Tricky way of of creating a generator via a comprehension expression
- Next message (by thread): [Python-Dev] Tricky way of of creating a generator via a comprehension expression
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]