mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-07-04 20:33:13 +03:00
Replace __isawaitable() with __is_future_or_coroutine()
This commit is contained in:
parent
3a4a3ceff7
commit
adf1bc7f79
File diff suppressed because it is too large
Load Diff
|
@ -6,7 +6,6 @@ except ImportError:
|
||||||
asyncio = None
|
asyncio = None
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
import inspect
|
|
||||||
|
|
||||||
cimport cython
|
cimport cython
|
||||||
|
|
||||||
|
@ -374,7 +373,7 @@ cdef inline object __provide_positional_args(
|
||||||
value = __get_value(injection)
|
value = __get_value(injection)
|
||||||
positional_args.append(value)
|
positional_args.append(value)
|
||||||
|
|
||||||
if __isawaitable(value):
|
if __is_future_or_coroutine(value):
|
||||||
awaitables.append((index, value))
|
awaitables.append((index, value))
|
||||||
|
|
||||||
positional_args.extend(args)
|
positional_args.extend(args)
|
||||||
|
@ -405,7 +404,7 @@ cdef inline object __provide_keyword_args(
|
||||||
name = __get_name(kw_injection)
|
name = __get_name(kw_injection)
|
||||||
value = __get_value(kw_injection)
|
value = __get_value(kw_injection)
|
||||||
kwargs[name] = value
|
kwargs[name] = value
|
||||||
if __isawaitable(value):
|
if __is_future_or_coroutine(value):
|
||||||
awaitables.append((name, value))
|
awaitables.append((name, value))
|
||||||
else:
|
else:
|
||||||
kwargs, prefixed = __separate_prefixed_kwargs(kwargs)
|
kwargs, prefixed = __separate_prefixed_kwargs(kwargs)
|
||||||
|
@ -424,7 +423,7 @@ cdef inline object __provide_keyword_args(
|
||||||
value = __get_value(kw_injection)
|
value = __get_value(kw_injection)
|
||||||
|
|
||||||
kwargs[name] = value
|
kwargs[name] = value
|
||||||
if __isawaitable(value):
|
if __is_future_or_coroutine(value):
|
||||||
awaitables.append((name, value))
|
awaitables.append((name, value))
|
||||||
|
|
||||||
if awaitables:
|
if awaitables:
|
||||||
|
@ -479,7 +478,7 @@ cdef inline object __provide_attributes(tuple attributes, int attributes_len):
|
||||||
name = __get_name(attr_injection)
|
name = __get_name(attr_injection)
|
||||||
value = __get_value(attr_injection)
|
value = __get_value(attr_injection)
|
||||||
attribute_injections[name] = value
|
attribute_injections[name] = value
|
||||||
if __isawaitable(value):
|
if __is_future_or_coroutine(value):
|
||||||
awaitables.append((name, value))
|
awaitables.append((name, value))
|
||||||
|
|
||||||
if awaitables:
|
if awaitables:
|
||||||
|
@ -540,8 +539,8 @@ cdef inline object __call(
|
||||||
injection_kwargs_len,
|
injection_kwargs_len,
|
||||||
)
|
)
|
||||||
|
|
||||||
args_awaitable = __isawaitable(args)
|
args_awaitable = __is_future_or_coroutine(args)
|
||||||
kwargs_awaitable = __isawaitable(kwargs)
|
kwargs_awaitable = __is_future_or_coroutine(kwargs)
|
||||||
|
|
||||||
if args_awaitable or kwargs_awaitable:
|
if args_awaitable or kwargs_awaitable:
|
||||||
if not args_awaitable:
|
if not args_awaitable:
|
||||||
|
@ -573,7 +572,7 @@ cdef inline void __async_call_callback(object future_result, object call, object
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
future_result.set_exception(exception)
|
future_result.set_exception(exception)
|
||||||
else:
|
else:
|
||||||
if __isawaitable(result):
|
if __is_future_or_coroutine(result):
|
||||||
result = asyncio.ensure_future(result)
|
result = asyncio.ensure_future(result)
|
||||||
result.add_done_callback(functools.partial(__async_result_callback, future_result))
|
result.add_done_callback(functools.partial(__async_result_callback, future_result))
|
||||||
return
|
return
|
||||||
|
@ -609,8 +608,8 @@ cdef inline object __factory_call(Factory self, tuple args, dict kwargs):
|
||||||
if self.__attributes_len > 0:
|
if self.__attributes_len > 0:
|
||||||
attributes = __provide_attributes(self.__attributes, self.__attributes_len)
|
attributes = __provide_attributes(self.__attributes, self.__attributes_len)
|
||||||
|
|
||||||
instance_awaitable = __isawaitable(instance)
|
instance_awaitable = __is_future_or_coroutine(instance)
|
||||||
attributes_awaitable = __isawaitable(attributes)
|
attributes_awaitable = __is_future_or_coroutine(attributes)
|
||||||
|
|
||||||
if instance_awaitable or attributes_awaitable:
|
if instance_awaitable or attributes_awaitable:
|
||||||
if not instance_awaitable:
|
if not instance_awaitable:
|
||||||
|
@ -624,22 +623,6 @@ cdef inline object __factory_call(Factory self, tuple args, dict kwargs):
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
||||||
cdef bint __has_isawaitable = False
|
|
||||||
|
|
||||||
|
|
||||||
cdef inline bint __isawaitable(object instance):
|
|
||||||
global __has_isawaitable
|
|
||||||
|
|
||||||
if __has_isawaitable is True:
|
|
||||||
return inspect.isawaitable(instance)
|
|
||||||
|
|
||||||
if hasattr(inspect, 'isawaitable'):
|
|
||||||
__has_isawaitable = True
|
|
||||||
return inspect.isawaitable(instance)
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
cdef inline bint __is_future_or_coroutine(object instance):
|
cdef inline bint __is_future_or_coroutine(object instance):
|
||||||
if asyncio is None:
|
if asyncio is None:
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Reference in New Issue
Block a user