I am trying to make my code better by omitting mutable list and replacing comprehension. There is a nested 'for' iterator which the inner is async. Here is the working code:
async def get_accumulator_providers(order: OrderDTO) -> Tuple[str, ...]:
bucket_mapping = await read_config(order)
result = []
for bucket in bucket_mapping:
async for item in dispatch_bucket(order, bucket, bucket_mapping[bucket], frozenset(accumulator_filters)):
result.append(item)
return tuple(result)
But when I use this code instead:
async def get_accumulator_providers(order: OrderDTO) -> Tuple[str, ...]:
bucket_mapping = await read_config(order)
return tuple(item for bucket in bucket_mapping async for item in
dispatch_bucket(order, bucket, bucket_mapping[bucket], frozenset(accumulator_filters)))
I get this error:
'async_generator' object is not iterable
What is the problem with my nested comprehension?