This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author levkivskyi
Recipients levkivskyi, yselivanov
Date 2017-11-22.14:42:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1511361761.52.0.213398074469.issue32113@psf.upfronthosting.co.za>
In-reply-to
Content
PEP 530 is not very clear about `await` in generator expressions. But when I try it, the error is a bit confusing:

>>> async def g(i):
...     print(i)
... 
>>> async def f():
...     result = list(await g(i) for i in range(3))
...     print(result)
... 
>>> f().send(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in f
TypeError: 'async_generator' object is not iterable

At the same time a (seemingly) equivalent list comprehension works fine:

>>> async def f():
...     result = [await g(i) for i in range(3)]
...     print(result)
... 
>>> f().send(None)
0
1
2
[None, None, None]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration

I would say that the first case should either behave as a second one, or raise a syntax error.

Or is it actually an intended behavior?
History
Date User Action Args
2017-11-22 14:42:41levkivskyisetrecipients: + levkivskyi, yselivanov
2017-11-22 14:42:41levkivskyisetmessageid: <1511361761.52.0.213398074469.issue32113@psf.upfronthosting.co.za>
2017-11-22 14:42:41levkivskyilinkissue32113 messages
2017-11-22 14:42:41levkivskyicreate