1
0
mirror of https://github.com/ARM-software/devlib.git synced 2024-10-05 18:30:50 +01:00

utils/asyn: Ensure _AsyncPolymorphicFunction is not detected as a coroutine function

inspect.iscoroutinefunction() currently detects
_AsyncPolymorphicFunction() as being a coroutine function since it
inspects x.__code__.co_flags to determine so. Since we delegate
attribute access to the async function, it makes
_AsyncPolymorphicFunction() appear as being a coroutine function even
though it is not.

Fix that by directing __code__ attribute access to __call__'s code.
This commit is contained in:
Douglas Raillard 2024-08-15 10:44:09 +01:00 committed by Marc Bonnici
parent b6da67d12f
commit 8773c10424

View File

@ -217,6 +217,12 @@ class _AsyncPolymorphicFunction:
blocking=self.blocking.__get__(*args, **kwargs),
)
# Ensure inspect.iscoroutinefunction() does not detect us as being async,
# since __call__ is not.
@property
def __code__(self):
return self.__call__.__code__
def __call__(self, *args, **kwargs):
return self.blocking(*args, **kwargs)