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

2017年11月22日 08:22:46 -0800

On 22 November 2017 at 15:56, Yury Selivanov <[email protected]> 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
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to