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/150696.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 expressionPaul Moore p.f.moore at gmail.com
Wed Nov 22 11:19:29 EST 2017
On 22 November 2017 at 15:56, Yury Selivanov <yselivanov.ml at gmail.com> wrote:
> For synchronous generator expression:
>
>    r = (f(i) for i in range(3))
>
> is really:
>
>    def _():
>       for i in range(3):
>         yield f(i)
>    r = _()
>
> For an asynchronous generator expression:
>
>    r = (await f(i) for i in range(3))
>
> is equivalent to:
>
>    def _():
>       for i in range(3):
>         yield (await f(i))
>    r = _()

Wait, I missed this on first reading. The note in the docs for
generator expressions defining asynchronous generator expressions is
*incredibly* easy to miss, and doesn't say anything about the
semantics (the expansion you quote above) being different for the two
cases. This definitely needs clarifying in the docs.

Paul
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