Refactor async mode checks

This commit is contained in:
Roman Mogylatov 2022-03-27 22:15:56 -04:00
parent 750445c5d1
commit bc50c5859e
3 changed files with 349 additions and 500 deletions

File diff suppressed because it is too large Load Diff

View File

@ -4106,7 +4106,6 @@ static const char __pyx_k_ContextLocalSingleton[] = "ContextLocalSingleton";
static const char __pyx_k_DependenciesContainer[] = "DependenciesContainer";
static const char __pyx_k_SingletonResetContext[] = "SingletonResetContext";
static const char __pyx_k_get_pydantic_settings[] = "get_pydantic_settings";
static const char __pyx_k_is_async_mode_enabled[] = "is_async_mode_enabled";
static const char __pyx_k_iscoroutine_typecache[] = "__iscoroutine_typecache";
static const char __pyx_k_pyx_unpickle_Callable[] = "__pyx_unpickle_Callable";
static const char __pyx_k_pyx_unpickle_Delegate[] = "__pyx_unpickle_Delegate";
@ -4120,7 +4119,6 @@ static const char __pyx_k_resolve_string_import[] = "_resolve_string_import";
static const char __pyx_k_set_pydantic_settings[] = "set_pydantic_settings";
static const char __pyx_k_ProvidedInstance___get[] = "ProvidedInstance.__get__";
static const char __pyx_k_create_shutdown_future[] = "_create_shutdown_future";
static const char __pyx_k_is_async_mode_disabled[] = "is_async_mode_disabled";
static const char __pyx_k_is_strict_mode_enabled[] = "_is_strict_mode_enabled";
static const char __pyx_k_pyx_unpickle_Aggregate[] = "__pyx_unpickle_Aggregate";
static const char __pyx_k_pyx_unpickle_Container[] = "__pyx_unpickle_Container";
@ -4130,7 +4128,6 @@ static const char __pyx_k_pyx_unpickle_Singleton[] = "__pyx_unpickle_Singleton";
static const char __pyx_k_resolve_calling_module[] = "_resolve_calling_module";
static const char __pyx_k_async_shutdown_callback[] = "_async_shutdown_callback";
static const char __pyx_k_asyncio_future_blocking[] = "_asyncio_future_blocking";
static const char __pyx_k_is_async_mode_undefined[] = "is_async_mode_undefined";
static const char __pyx_k_pyx_unpickle_Dependency[] = "__pyx_unpickle_Dependency";
static const char __pyx_k_pyx_unpickle_ItemGetter[] = "__pyx_unpickle_ItemGetter";
static const char __pyx_k_TypedConfigurationOption[] = "TypedConfigurationOption";
@ -4588,9 +4585,6 @@ static PyObject *__pyx_n_s_instance;
static PyObject *__pyx_n_s_instance_of;
static PyObject *__pyx_kp_s_instance_of_has_incorrect_type;
static PyObject *__pyx_kp_u_instead;
static PyObject *__pyx_n_s_is_async_mode_disabled;
static PyObject *__pyx_n_s_is_async_mode_enabled;
static PyObject *__pyx_n_s_is_async_mode_undefined;
static PyObject *__pyx_n_s_is_async_resource_subclass;
static PyObject *__pyx_n_s_is_coroutine;
static PyObject *__pyx_n_s_is_coroutine_marker;
@ -18386,7 +18380,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_10Dependency_4__call_
* else:
* self._raise_undefined_error() # <<<<<<<<<<<<<<
*
* if self.is_async_mode_disabled():
* if self.__async_mode == ASYNC_MODE_DISABLED:
*/
/*else*/ {
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_raise_undefined_error); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 814, __pyx_L1_error)
@ -18413,37 +18407,19 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_10Dependency_4__call_
/* "dependency_injector/providers.pyx":816
* self._raise_undefined_error()
*
* if self.is_async_mode_disabled(): # <<<<<<<<<<<<<<
* if self.__async_mode == ASYNC_MODE_DISABLED: # <<<<<<<<<<<<<<
* self._check_instance_type(result)
* return result
*/
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_async_mode_disabled); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 816, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
if (likely(__pyx_t_4)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
__Pyx_INCREF(__pyx_t_4);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_3, function);
}
}
__pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 816, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 816, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_1 = ((__pyx_v_self->__pyx_base.__pyx___async_mode == __pyx_v_19dependency_injector_9providers_ASYNC_MODE_DISABLED) != 0);
if (__pyx_t_1) {
/* "dependency_injector/providers.pyx":817
*
* if self.is_async_mode_disabled():
* if self.__async_mode == ASYNC_MODE_DISABLED:
* self._check_instance_type(result) # <<<<<<<<<<<<<<
* return result
* elif self.is_async_mode_enabled():
* elif self.__async_mode == ASYNC_MODE_ENABLED:
*/
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_instance_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 817, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
@ -18466,10 +18442,10 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_10Dependency_4__call_
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
/* "dependency_injector/providers.pyx":818
* if self.is_async_mode_disabled():
* if self.__async_mode == ASYNC_MODE_DISABLED:
* self._check_instance_type(result)
* return result # <<<<<<<<<<<<<<
* elif self.is_async_mode_enabled():
* elif self.__async_mode == ASYNC_MODE_ENABLED:
* if __is_future_or_coroutine(result):
*/
__Pyx_XDECREF(__pyx_r);
@ -18481,7 +18457,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_10Dependency_4__call_
/* "dependency_injector/providers.pyx":816
* self._raise_undefined_error()
*
* if self.is_async_mode_disabled(): # <<<<<<<<<<<<<<
* if self.__async_mode == ASYNC_MODE_DISABLED: # <<<<<<<<<<<<<<
* self._check_instance_type(result)
* return result
*/
@ -18490,34 +18466,16 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_10Dependency_4__call_
/* "dependency_injector/providers.pyx":819
* self._check_instance_type(result)
* return result
* elif self.is_async_mode_enabled(): # <<<<<<<<<<<<<<
* elif self.__async_mode == ASYNC_MODE_ENABLED: # <<<<<<<<<<<<<<
* if __is_future_or_coroutine(result):
* future_result = asyncio.Future()
*/
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_async_mode_enabled); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 819, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
if (likely(__pyx_t_4)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
__Pyx_INCREF(__pyx_t_4);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_3, function);
}
}
__pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 819, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 819, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_1 = ((__pyx_v_self->__pyx_base.__pyx___async_mode == __pyx_v_19dependency_injector_9providers_ASYNC_MODE_ENABLED) != 0);
if (__pyx_t_1) {
/* "dependency_injector/providers.pyx":820
* return result
* elif self.is_async_mode_enabled():
* elif self.__async_mode == ASYNC_MODE_ENABLED:
* if __is_future_or_coroutine(result): # <<<<<<<<<<<<<<
* future_result = asyncio.Future()
* result = asyncio.ensure_future(result)
@ -18527,7 +18485,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_10Dependency_4__call_
if (__pyx_t_1) {
/* "dependency_injector/providers.pyx":821
* elif self.is_async_mode_enabled():
* elif self.__async_mode == ASYNC_MODE_ENABLED:
* if __is_future_or_coroutine(result):
* future_result = asyncio.Future() # <<<<<<<<<<<<<<
* result = asyncio.ensure_future(result)
@ -18682,7 +18640,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_10Dependency_4__call_
/* "dependency_injector/providers.pyx":820
* return result
* elif self.is_async_mode_enabled():
* elif self.__async_mode == ASYNC_MODE_ENABLED:
* if __is_future_or_coroutine(result): # <<<<<<<<<<<<<<
* future_result = asyncio.Future()
* result = asyncio.ensure_future(result)
@ -18694,7 +18652,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_10Dependency_4__call_
* else:
* self._check_instance_type(result) # <<<<<<<<<<<<<<
* return __future_result(result)
* elif self.is_async_mode_undefined():
* elif self.__async_mode == ASYNC_MODE_UNDEFINED:
*/
/*else*/ {
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_instance_type); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 826, __pyx_L1_error)
@ -18721,7 +18679,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_10Dependency_4__call_
* else:
* self._check_instance_type(result)
* return __future_result(result) # <<<<<<<<<<<<<<
* elif self.is_async_mode_undefined():
* elif self.__async_mode == ASYNC_MODE_UNDEFINED:
* if __is_future_or_coroutine(result):
*/
__Pyx_XDECREF(__pyx_r);
@ -18736,7 +18694,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_10Dependency_4__call_
/* "dependency_injector/providers.pyx":819
* self._check_instance_type(result)
* return result
* elif self.is_async_mode_enabled(): # <<<<<<<<<<<<<<
* elif self.__async_mode == ASYNC_MODE_ENABLED: # <<<<<<<<<<<<<<
* if __is_future_or_coroutine(result):
* future_result = asyncio.Future()
*/
@ -18745,34 +18703,16 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_10Dependency_4__call_
/* "dependency_injector/providers.pyx":828
* self._check_instance_type(result)
* return __future_result(result)
* elif self.is_async_mode_undefined(): # <<<<<<<<<<<<<<
* elif self.__async_mode == ASYNC_MODE_UNDEFINED: # <<<<<<<<<<<<<<
* if __is_future_or_coroutine(result):
* self.enable_async_mode()
*/
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_async_mode_undefined); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 828, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
if (likely(__pyx_t_4)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
__Pyx_INCREF(__pyx_t_4);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_3, function);
}
}
__pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 828, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 828, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_1 = ((__pyx_v_self->__pyx_base.__pyx___async_mode == __pyx_v_19dependency_injector_9providers_ASYNC_MODE_UNDEFINED) != 0);
if (__pyx_t_1) {
/* "dependency_injector/providers.pyx":829
* return __future_result(result)
* elif self.is_async_mode_undefined():
* elif self.__async_mode == ASYNC_MODE_UNDEFINED:
* if __is_future_or_coroutine(result): # <<<<<<<<<<<<<<
* self.enable_async_mode()
*
@ -18782,7 +18722,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_10Dependency_4__call_
if (__pyx_t_1) {
/* "dependency_injector/providers.pyx":830
* elif self.is_async_mode_undefined():
* elif self.__async_mode == ASYNC_MODE_UNDEFINED:
* if __is_future_or_coroutine(result):
* self.enable_async_mode() # <<<<<<<<<<<<<<
*
@ -18963,7 +18903,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_10Dependency_4__call_
/* "dependency_injector/providers.pyx":829
* return __future_result(result)
* elif self.is_async_mode_undefined():
* elif self.__async_mode == ASYNC_MODE_UNDEFINED:
* if __is_future_or_coroutine(result): # <<<<<<<<<<<<<<
* self.enable_async_mode()
*
@ -19041,7 +18981,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_10Dependency_4__call_
/* "dependency_injector/providers.pyx":828
* self._check_instance_type(result)
* return __future_result(result)
* elif self.is_async_mode_undefined(): # <<<<<<<<<<<<<<
* elif self.__async_mode == ASYNC_MODE_UNDEFINED: # <<<<<<<<<<<<<<
* if __is_future_or_coroutine(result):
* self.enable_async_mode()
*/
@ -70697,7 +70637,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Resource_22shutdown(
* def shutdown(self):
* """Shutdown resource."""
* if not self.__initialized: # <<<<<<<<<<<<<<
* if self.is_async_mode_enabled():
* if self.__async_mode == ASYNC_MODE_ENABLED:
* result = asyncio.Future()
*/
__pyx_t_1 = ((!(__pyx_v_self->__pyx___initialized != 0)) != 0);
@ -70706,34 +70646,16 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Resource_22shutdown(
/* "dependency_injector/providers.pyx":3696
* """Shutdown resource."""
* if not self.__initialized:
* if self.is_async_mode_enabled(): # <<<<<<<<<<<<<<
* if self.__async_mode == ASYNC_MODE_ENABLED: # <<<<<<<<<<<<<<
* result = asyncio.Future()
* result.set_result(None)
*/
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_async_mode_enabled); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3696, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
if (likely(__pyx_t_4)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
__Pyx_INCREF(__pyx_t_4);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_3, function);
}
}
__pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3696, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 3696, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_1 = ((__pyx_v_self->__pyx_base.__pyx___async_mode == __pyx_v_19dependency_injector_9providers_ASYNC_MODE_ENABLED) != 0);
if (__pyx_t_1) {
/* "dependency_injector/providers.pyx":3697
* if not self.__initialized:
* if self.is_async_mode_enabled():
* if self.__async_mode == ASYNC_MODE_ENABLED:
* result = asyncio.Future() # <<<<<<<<<<<<<<
* result.set_result(None)
* return result
@ -70762,7 +70684,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Resource_22shutdown(
__pyx_t_2 = 0;
/* "dependency_injector/providers.pyx":3698
* if self.is_async_mode_enabled():
* if self.__async_mode == ASYNC_MODE_ENABLED:
* result = asyncio.Future()
* result.set_result(None) # <<<<<<<<<<<<<<
* return result
@ -70802,7 +70724,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Resource_22shutdown(
/* "dependency_injector/providers.pyx":3696
* """Shutdown resource."""
* if not self.__initialized:
* if self.is_async_mode_enabled(): # <<<<<<<<<<<<<<
* if self.__async_mode == ASYNC_MODE_ENABLED: # <<<<<<<<<<<<<<
* result = asyncio.Future()
* result.set_result(None)
*/
@ -70823,7 +70745,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Resource_22shutdown(
* def shutdown(self):
* """Shutdown resource."""
* if not self.__initialized: # <<<<<<<<<<<<<<
* if self.is_async_mode_enabled():
* if self.__async_mode == ASYNC_MODE_ENABLED:
* result = asyncio.Future()
*/
}
@ -71045,7 +70967,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Resource_22shutdown(
* self.__initialized = False
* self.__shutdowner = None # <<<<<<<<<<<<<<
*
* if self.is_async_mode_enabled():
* if self.__async_mode == ASYNC_MODE_ENABLED:
*/
__Pyx_INCREF(Py_None);
__Pyx_GIVEREF(Py_None);
@ -71056,34 +70978,16 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Resource_22shutdown(
/* "dependency_injector/providers.pyx":3715
* self.__shutdowner = None
*
* if self.is_async_mode_enabled(): # <<<<<<<<<<<<<<
* if self.__async_mode == ASYNC_MODE_ENABLED: # <<<<<<<<<<<<<<
* result = asyncio.Future()
* result.set_result(None)
*/
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_async_mode_enabled); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 3715, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
if (likely(__pyx_t_4)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
__Pyx_INCREF(__pyx_t_4);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_3, function);
}
}
__pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3715, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 3715, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_1 = ((__pyx_v_self->__pyx_base.__pyx___async_mode == __pyx_v_19dependency_injector_9providers_ASYNC_MODE_ENABLED) != 0);
if (__pyx_t_1) {
/* "dependency_injector/providers.pyx":3716
*
* if self.is_async_mode_enabled():
* if self.__async_mode == ASYNC_MODE_ENABLED:
* result = asyncio.Future() # <<<<<<<<<<<<<<
* result.set_result(None)
* return result
@ -71112,7 +71016,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Resource_22shutdown(
__pyx_t_2 = 0;
/* "dependency_injector/providers.pyx":3717
* if self.is_async_mode_enabled():
* if self.__async_mode == ASYNC_MODE_ENABLED:
* result = asyncio.Future()
* result.set_result(None) # <<<<<<<<<<<<<<
* return result
@ -71152,7 +71056,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Resource_22shutdown(
/* "dependency_injector/providers.pyx":3715
* self.__shutdowner = None
*
* if self.is_async_mode_enabled(): # <<<<<<<<<<<<<<
* if self.__async_mode == ASYNC_MODE_ENABLED: # <<<<<<<<<<<<<<
* result = asyncio.Future()
* result.set_result(None)
*/
@ -137560,9 +137464,6 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_n_s_instance_of, __pyx_k_instance_of, sizeof(__pyx_k_instance_of), 0, 0, 1, 1},
{&__pyx_kp_s_instance_of_has_incorrect_type, __pyx_k_instance_of_has_incorrect_type, sizeof(__pyx_k_instance_of_has_incorrect_type), 0, 0, 1, 0},
{&__pyx_kp_u_instead, __pyx_k_instead, sizeof(__pyx_k_instead), 0, 1, 0, 0},
{&__pyx_n_s_is_async_mode_disabled, __pyx_k_is_async_mode_disabled, sizeof(__pyx_k_is_async_mode_disabled), 0, 0, 1, 1},
{&__pyx_n_s_is_async_mode_enabled, __pyx_k_is_async_mode_enabled, sizeof(__pyx_k_is_async_mode_enabled), 0, 0, 1, 1},
{&__pyx_n_s_is_async_mode_undefined, __pyx_k_is_async_mode_undefined, sizeof(__pyx_k_is_async_mode_undefined), 0, 0, 1, 1},
{&__pyx_n_s_is_async_resource_subclass, __pyx_k_is_async_resource_subclass, sizeof(__pyx_k_is_async_resource_subclass), 0, 0, 1, 1},
{&__pyx_n_s_is_coroutine, __pyx_k_is_coroutine, sizeof(__pyx_k_is_coroutine), 0, 0, 1, 1},
{&__pyx_n_s_is_coroutine_marker, __pyx_k_is_coroutine_marker, sizeof(__pyx_k_is_coroutine_marker), 0, 0, 1, 1},

View File

@ -813,10 +813,10 @@ cdef class Dependency(Provider):
else:
self._raise_undefined_error()
if self.is_async_mode_disabled():
if self.__async_mode == ASYNC_MODE_DISABLED:
self._check_instance_type(result)
return result
elif self.is_async_mode_enabled():
elif self.__async_mode == ASYNC_MODE_ENABLED:
if __is_future_or_coroutine(result):
future_result = asyncio.Future()
result = asyncio.ensure_future(result)
@ -825,7 +825,7 @@ cdef class Dependency(Provider):
else:
self._check_instance_type(result)
return __future_result(result)
elif self.is_async_mode_undefined():
elif self.__async_mode == ASYNC_MODE_UNDEFINED:
if __is_future_or_coroutine(result):
self.enable_async_mode()
@ -3693,7 +3693,7 @@ cdef class Resource(Provider):
def shutdown(self):
"""Shutdown resource."""
if not self.__initialized:
if self.is_async_mode_enabled():
if self.__async_mode == ASYNC_MODE_ENABLED:
result = asyncio.Future()
result.set_result(None)
return result
@ -3712,7 +3712,7 @@ cdef class Resource(Provider):
self.__initialized = False
self.__shutdowner = None
if self.is_async_mode_enabled():
if self.__async_mode == ASYNC_MODE_ENABLED:
result = asyncio.Future()
result.set_result(None)
return result