Issue
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?
Solution
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
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.