Message306732
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? |
|
Date |
User |
Action |
Args |
2017-11-22 14:42:41 | levkivskyi | set | recipients:
+ levkivskyi, yselivanov |
2017-11-22 14:42:41 | levkivskyi | set | messageid: <1511361761.52.0.213398074469.issue32113@psf.upfronthosting.co.za> |
2017-11-22 14:42:41 | levkivskyi | link | issue32113 messages |
2017-11-22 14:42:41 | levkivskyi | create | |
|