Skip to content

Commit

Permalink
fix: update async wrapper to keep function signature
Browse files Browse the repository at this point in the history
  • Loading branch information
hlouzada committed Mar 4, 2024
1 parent 12103eb commit adf1ddc
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions spyder/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""
API utilities.
"""
import functools
import asyncio


Expand Down Expand Up @@ -102,10 +103,17 @@ def __init__(self, coro, loop=None):
loop : asyncio.AbstractEventLoop, optional
The event loop to be used, by default get the current event loop.
"""
self.coro = coro
self.loop = loop or asyncio.get_event_loop()
self.__coro = coro
self.__loop = loop or asyncio.get_event_loop()
functools.update_wrapper(self, coro)

def __call__(self, *args, **kwargs):
"""Call the coroutine as a sync function."""
return self.loop.run_until_complete(self.coro(*args, **kwargs))
return self.__loop.run_until_complete(self.__coro(*args, **kwargs))

def __get__(self, instance, owner):
if instance is None:
return self
else:
bound_method = self.__coro.__get__(instance, owner)
return functools.partial(self.__class__(bound_method, self.__loop))

0 comments on commit adf1ddc

Please sign in to comment.