[Python-Dev] Tricky way of of creating a generator via a comprehension expression
Yury Selivanov
yselivanov.ml at gmail.com
Wed Nov 22 19:00:36 EST 2017
On Wed, Nov 22, 2017 at 6:46 PM, Ivan Levkivskyi <levkivskyi at gmail.com> wrote:
[..]
> Just found another example of intuitive behaviour:
>
>>>> async def f():
> ... for i in range(3):
> ... yield i
> ...
>>>> async def g():
> ... return [(yield i) async for i in f()]
> ...
>>>> g().send(None)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "<stdin>", line 2, in g
> TypeError: object async_generator can't be used in 'await' expression
>
> of course it is obvious for anyone who writes async code, but anyway an
> interesting example.
I wouldn't say that it's obvious to anyone...
I think this thread has started to discuss the use of 'yield'
expression in comprehensions, and the outcome of the discussion is
that everyone thinks that we should deprecate that syntax in 3.7,
remove in 3.8. Let's start with that? :)
Yury
More information about the Python-Dev
mailing list