I am trying to replicate the following from PEP 530
generator expression: (i ** 2 async for i in agen()).
with the following code:
import asyncio async def agen(): for x in range(5): yield x async def main(): x = tuple(i ** 2 async for i in agen()) print(x) asyncio.run(main())
but I get
TypeError: 'async_generator' object is not iterable. If I do
x = [i ** 2 async for i in agen()] works well.
I understand that the faulty statement is equivalent of
tuple(agen()). Then, how / when am I expected to use async generator expressions? Could I get an example?