async generator returned from intermediate function raising TypeError

Question:

I’ve got a generator like this:

async def blah1(v):
  ...
  async for blah in blahblah(v):
    yield blah

async def intermediateblah(v):
  return await blah1(v)

And I’m trying to do a list comprehension:

assert [x async for x in await intermediateblah("*")] == ["a"]

But I’m getting this error: TypeError: object async_generator can't be used in 'await' expression I think my main problem is that in intermediateblah, I have to await blah1 since there are some other code pieces that require me to use await.

Anyone know how I can do this list comprehension? Or just a for loop in general?

Asked By: acw

||

Answers:

You don’t await an async generator, just like you do not call a plain one returned by a function.

Simply return it

async def intermediateblah(v):
  return blah1(v)
Answered By: Pynchia
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.