You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When passing firstresult=True to a hookspec marker, the HookCaller will only return 1 result (coroutine) instead of a list of results but asyncio.gather expect a list of "tasks" and not a single coroutine
Here's a minimally reproducible example to illustrate the issue.
The code above fails with TypeError: asyncio.tasks.gather() argument after * must be an iterable, not coroutine
but changing the call function to actually check whether calling hook(*args, **kwargs) returns a list and acting accordingly if it doesn't fixes the issue.
classAHook:
def__init__(self, pm: PluginManager_) ->None:
self.pm=pmdef__getattr__(self, name: str) ->Callable[..., Coroutine[Any, Any, list]]:
asyncdefcall(*args: Any, **kwargs: Any) ->list:
hook: HookCaller=getattr(self.pm.hook, name)
coros: list[asyncio.Future] =hook(*args, **kwargs)
ifnotisinstance(coros, Coroutine):
returnNoneifnotisinstance(coros, list): # Added an isinstance check to see whether a list or a single element is returnedreturnawaitcorosreturnawaitasyncio.gather(*coros)
returncall
After this small change the code works as expected:
print(awaitpm.ahook.afunc(x=1, y=2))
>>>3
The text was updated successfully, but these errors were encountered:
When passing
firstresult=True
to a hookspec marker, the HookCaller will only return 1 result (coroutine) instead of a list of results butasyncio.gather
expect a list of "tasks" and not a single coroutineHere's a minimally reproducible example to illustrate the issue.
The code above fails with
TypeError: asyncio.tasks.gather() argument after * must be an iterable, not coroutine
but changing the
call
function to actually check whether callinghook(*args, **kwargs)
returns a list and acting accordingly if it doesn't fixes the issue.After this small change the code works as expected:
The text was updated successfully, but these errors were encountered: