[Python-Dev] Tricky way of of creating a generator via a comprehension expression (original) (raw)
Ethan Furman ethan at stoneleaf.us
Fri Nov 24 21:09:24 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 11/24/2017 04:22 PM, Guido van Rossum 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
.
For me, the deciding factor would be the the affect upon:
- the containing function (if any); and
- the result of the genexp/comprehension
I think of generator expressions / comprehensions as self-contained units of code that will have no (side-)effects upon the containing function and/or surrounding code (and a containing function is not necessary), and that each will return the type expressed by the syntax.
In other words:
[ l for l in ...] -> list {s for s in ...] -> set {k:v for k, v in ...] -> dict (g for g in ...] -> genexp
Since 'yield' and 'yield from' invalidate those, I'm in favor of declaring them syntax errors.
If 'await' does not invalidate the above constraints then I'm fine with allowing them.
--
Ethan
- 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 ]