def is_awaitable(obj):
# There is no single method which can answer in any case, should wait or not - so need to create one
# for the suspected cases : func, coro, gen-coro, future,
# class with sync __call__, class with async __call__,
# sync method, async method
if inspect.isawaitable(obj) or inspect.iscoroutinefunction(obj) or inspect.iscoroutine(obj):
return True
elif inspect.isgeneratorfunction(obj):
return True
elif CallChain.is_user_defined_class(obj):
if hasattr(obj, '__call__'):
return CallChain.is_awaitable(obj.__call__)
return False
else:
return False
评论列表
文章目录