A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2017-November/150729.html below:

[Python-Dev] Tricky way of of creating a generator via a comprehension expression

[Python-Dev] Tricky way of of creating a generator via a comprehension expression [Python-Dev] Tricky way of of creating a generator via a comprehension expressionGreg Ewing greg.ewing at canterbury.ac.nz
Wed Nov 22 17:14:41 EST 2017
Ivan Levkivskyi wrote:
> while `g = list((yield i) for i in range(3))` is defined as this code:
> 
>     def __gen():
>        for i in range(3):
>          yield (yield i)
>     g = list(__gen())

Since this is almost certainly not what was intended, I think that
'yield' inside a generator expression should simply be disallowed.

The problem with making it work intuitively is that there's no way
to distinguish between the implicit yields producing values for the
generator comprehension and the explicit ones that the programmer
is expecting to be passed through and yielded from the enclosing
generator function.

Fixing that would require adding another whole layer of complexity
similar to what Yuri did to support async generators, and I can't
see that being worth the effort.

-- 
Greg
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4