diff --git a/src/dependency_injector/providers.c b/src/dependency_injector/providers.c index dc6efa27..fe9a2e61 100644 --- a/src/dependency_injector/providers.c +++ b/src/dependency_injector/providers.c @@ -3436,6 +3436,7 @@ static const char __pyx_k_OverridingContext[] = "OverridingContext"; static const char __pyx_k_SingletonDelegate[] = "SingletonDelegate"; static const char __pyx_k_add_done_callback[] = "add_done_callback"; static const char __pyx_k_deepcopy_dispatch[] = "_deepcopy_dispatch"; +static const char __pyx_k_enable_async_mode[] = "enable_async_mode"; static const char __pyx_k_pyx_unpickle_Dict[] = "__pyx_unpickle_Dict"; static const char __pyx_k_pyx_unpickle_List[] = "__pyx_unpickle_List"; static const char __pyx_k_BasicInterpolation[] = "BasicInterpolation"; @@ -3446,6 +3447,7 @@ static const char __pyx_k_ExternalDependency[] = "ExternalDependency"; static const char __pyx_k_asyncio_coroutines[] = "asyncio.coroutines"; static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; static const char __pyx_k_create_init_future[] = "_create_init_future"; +static const char __pyx_k_disable_async_mode[] = "disable_async_mode"; static const char __pyx_k_isasyncgenfunction[] = "isasyncgenfunction"; static const char __pyx_k_override_providers[] = "_override_providers"; static const char __pyx_k_ConfigurationOption[] = "ConfigurationOption"; @@ -3467,6 +3469,7 @@ static const char __pyx_k_pyx_unpickle_Factory[] = "__pyx_unpickle_Factory"; static const char __pyx_k_str___locals_genexpr[] = "__str__..genexpr"; static const char __pyx_k_DependenciesContainer[] = "DependenciesContainer"; static const char __pyx_k_add_implicit_resolver[] = "add_implicit_resolver"; +static const char __pyx_k_is_async_mode_enabled[] = "is_async_mode_enabled"; static const char __pyx_k_pyx_unpickle_Callable[] = "__pyx_unpickle_Callable"; static const char __pyx_k_pyx_unpickle_Delegate[] = "__pyx_unpickle_Delegate"; static const char __pyx_k_pyx_unpickle_Provider[] = "__pyx_unpickle_Provider"; @@ -3474,11 +3477,13 @@ static const char __pyx_k_pyx_unpickle_Resource[] = "__pyx_unpickle_Resource"; static const char __pyx_k_pyx_unpickle_Selector[] = "__pyx_unpickle_Selector"; static const char __pyx_k_reset_last_overriding[] = "reset_last_overriding"; 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_pyx_unpickle_Container[] = "__pyx_unpickle_Container"; static const char __pyx_k_pyx_unpickle_Coroutine[] = "__pyx_unpickle_Coroutine"; static const char __pyx_k_pyx_unpickle_Injection[] = "__pyx_unpickle_Injection"; static const char __pyx_k_pyx_unpickle_Singleton[] = "__pyx_unpickle_Singleton"; static const char __pyx_k_async_shutdown_callback[] = "_async_shutdown_callback"; +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_yaml_env_marker_pattern[] = "yaml_env_marker_pattern"; @@ -3770,7 +3775,9 @@ static PyObject *__pyx_n_s_dict; static PyObject *__pyx_n_s_dict1; static PyObject *__pyx_n_s_dict2; static PyObject *__pyx_n_s_dict_2; +static PyObject *__pyx_n_s_disable_async_mode; static PyObject *__pyx_n_s_doc; +static PyObject *__pyx_n_s_enable_async_mode; static PyObject *__pyx_n_s_endswith; static PyObject *__pyx_n_s_ensure_future; static PyObject *__pyx_n_s_enter; @@ -3810,6 +3817,9 @@ static PyObject *__pyx_n_s_inspect; static PyObject *__pyx_n_s_instance; static PyObject *__pyx_n_s_instance_of; static PyObject *__pyx_n_s_interpolation; +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; @@ -6051,7 +6061,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Provider_2__call__(s * else: * result = self._provide(args, kwargs) # <<<<<<<<<<<<<< * - * if self.__async_mode == ASYNC_MODE_DISABLED: + * if self.is_async_mode_disabled(): */ /*else*/ { __pyx_t_3 = ((struct __pyx_vtabstruct_19dependency_injector_9providers_Provider *)__pyx_v_self->__pyx_vtab)->_provide(__pyx_v_self, __pyx_v_args, __pyx_v_kwargs, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 168, __pyx_L1_error) @@ -6064,18 +6074,36 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Provider_2__call__(s /* "dependency_injector/providers.pyx":170 * result = self._provide(args, kwargs) * - * if self.__async_mode == ASYNC_MODE_DISABLED: # <<<<<<<<<<<<<< + * if self.is_async_mode_disabled(): # <<<<<<<<<<<<<< * return result - * elif self.__async_mode == ASYNC_MODE_ENABLED: + * elif self.is_async_mode_enabled(): */ - __pyx_t_2 = ((__pyx_v_self->__pyx___async_mode == __pyx_v_19dependency_injector_9providers_ASYNC_MODE_DISABLED) != 0); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_async_mode_disabled); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 170, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 170, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 170, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_2) { /* "dependency_injector/providers.pyx":171 * - * if self.__async_mode == ASYNC_MODE_DISABLED: + * if self.is_async_mode_disabled(): * return result # <<<<<<<<<<<<<< - * elif self.__async_mode == ASYNC_MODE_ENABLED: + * elif self.is_async_mode_enabled(): * if not __isawaitable(result): */ __Pyx_XDECREF(__pyx_r); @@ -6086,25 +6114,43 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Provider_2__call__(s /* "dependency_injector/providers.pyx":170 * result = self._provide(args, kwargs) * - * if self.__async_mode == ASYNC_MODE_DISABLED: # <<<<<<<<<<<<<< + * if self.is_async_mode_disabled(): # <<<<<<<<<<<<<< * return result - * elif self.__async_mode == ASYNC_MODE_ENABLED: + * elif self.is_async_mode_enabled(): */ } /* "dependency_injector/providers.pyx":172 - * if self.__async_mode == ASYNC_MODE_DISABLED: + * if self.is_async_mode_disabled(): * return result - * elif self.__async_mode == ASYNC_MODE_ENABLED: # <<<<<<<<<<<<<< + * elif self.is_async_mode_enabled(): # <<<<<<<<<<<<<< * if not __isawaitable(result): * future_result = asyncio.Future() */ - __pyx_t_2 = ((__pyx_v_self->__pyx___async_mode == __pyx_v_19dependency_injector_9providers_ASYNC_MODE_ENABLED) != 0); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_async_mode_enabled); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 172, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 172, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 172, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_2) { /* "dependency_injector/providers.pyx":173 * return result - * elif self.__async_mode == ASYNC_MODE_ENABLED: + * elif self.is_async_mode_enabled(): * if not __isawaitable(result): # <<<<<<<<<<<<<< * future_result = asyncio.Future() * future_result.set_result(result) @@ -6113,7 +6159,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Provider_2__call__(s if (__pyx_t_2) { /* "dependency_injector/providers.pyx":174 - * elif self.__async_mode == ASYNC_MODE_ENABLED: + * elif self.is_async_mode_enabled(): * if not __isawaitable(result): * future_result = asyncio.Future() # <<<<<<<<<<<<<< * future_result.set_result(result) @@ -6173,7 +6219,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Provider_2__call__(s * future_result.set_result(result) * return future_result # <<<<<<<<<<<<<< * return result - * elif self.__async_mode == ASYNC_MODE_UNDEFINED: + * elif self.is_async_mode_undefined(): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_future_result); @@ -6182,7 +6228,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Provider_2__call__(s /* "dependency_injector/providers.pyx":173 * return result - * elif self.__async_mode == ASYNC_MODE_ENABLED: + * elif self.is_async_mode_enabled(): * if not __isawaitable(result): # <<<<<<<<<<<<<< * future_result = asyncio.Future() * future_result.set_result(result) @@ -6193,7 +6239,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Provider_2__call__(s * future_result.set_result(result) * return future_result * return result # <<<<<<<<<<<<<< - * elif self.__async_mode == ASYNC_MODE_UNDEFINED: + * elif self.is_async_mode_undefined(): * if __isawaitable(result): */ __Pyx_XDECREF(__pyx_r); @@ -6202,9 +6248,9 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Provider_2__call__(s goto __pyx_L0; /* "dependency_injector/providers.pyx":172 - * if self.__async_mode == ASYNC_MODE_DISABLED: + * if self.is_async_mode_disabled(): * return result - * elif self.__async_mode == ASYNC_MODE_ENABLED: # <<<<<<<<<<<<<< + * elif self.is_async_mode_enabled(): # <<<<<<<<<<<<<< * if not __isawaitable(result): * future_result = asyncio.Future() */ @@ -6213,57 +6259,109 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Provider_2__call__(s /* "dependency_injector/providers.pyx":178 * return future_result * return result - * elif self.__async_mode == ASYNC_MODE_UNDEFINED: # <<<<<<<<<<<<<< + * elif self.is_async_mode_undefined(): # <<<<<<<<<<<<<< * if __isawaitable(result): - * self.__async_mode = ASYNC_MODE_ENABLED + * self.enable_async_mode() */ - __pyx_t_2 = ((__pyx_v_self->__pyx___async_mode == __pyx_v_19dependency_injector_9providers_ASYNC_MODE_UNDEFINED) != 0); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_async_mode_undefined); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 178, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 178, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 178, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_2) { /* "dependency_injector/providers.pyx":179 * return result - * elif self.__async_mode == ASYNC_MODE_UNDEFINED: + * elif self.is_async_mode_undefined(): * if __isawaitable(result): # <<<<<<<<<<<<<< - * self.__async_mode = ASYNC_MODE_ENABLED + * self.enable_async_mode() * else: */ __pyx_t_2 = (__pyx_f_19dependency_injector_9providers___isawaitable(__pyx_v_result) != 0); if (__pyx_t_2) { /* "dependency_injector/providers.pyx":180 - * elif self.__async_mode == ASYNC_MODE_UNDEFINED: + * elif self.is_async_mode_undefined(): * if __isawaitable(result): - * self.__async_mode = ASYNC_MODE_ENABLED # <<<<<<<<<<<<<< + * self.enable_async_mode() # <<<<<<<<<<<<<< * else: - * self.__async_mode = ASYNC_MODE_DISABLED + * self.disable_async_mode() */ - __pyx_v_self->__pyx___async_mode = __pyx_v_19dependency_injector_9providers_ASYNC_MODE_ENABLED; + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_enable_async_mode); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 180, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 180, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "dependency_injector/providers.pyx":179 * return result - * elif self.__async_mode == ASYNC_MODE_UNDEFINED: + * elif self.is_async_mode_undefined(): * if __isawaitable(result): # <<<<<<<<<<<<<< - * self.__async_mode = ASYNC_MODE_ENABLED + * self.enable_async_mode() * else: */ goto __pyx_L6; } /* "dependency_injector/providers.pyx":182 - * self.__async_mode = ASYNC_MODE_ENABLED + * self.enable_async_mode() * else: - * self.__async_mode = ASYNC_MODE_DISABLED # <<<<<<<<<<<<<< + * self.disable_async_mode() # <<<<<<<<<<<<<< * return result * */ /*else*/ { - __pyx_v_self->__pyx___async_mode = __pyx_v_19dependency_injector_9providers_ASYNC_MODE_DISABLED; + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_disable_async_mode); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 182, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + __pyx_t_3 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 182, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L6:; /* "dependency_injector/providers.pyx":183 * else: - * self.__async_mode = ASYNC_MODE_DISABLED + * self.disable_async_mode() * return result # <<<<<<<<<<<<<< * * def __deepcopy__(self, memo): @@ -6276,9 +6374,9 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Provider_2__call__(s /* "dependency_injector/providers.pyx":178 * return future_result * return result - * elif self.__async_mode == ASYNC_MODE_UNDEFINED: # <<<<<<<<<<<<<< + * elif self.is_async_mode_undefined(): # <<<<<<<<<<<<<< * if __isawaitable(result): - * self.__async_mode = ASYNC_MODE_ENABLED + * self.enable_async_mode() */ } @@ -8209,7 +8307,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Provider_22disable_a /* Python wrapper */ static PyObject *__pyx_pw_19dependency_injector_9providers_8Provider_25reset_async_mode(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_19dependency_injector_9providers_8Provider_24reset_async_mode[] = "Reset async mode.\n\n Provider will automatically define the mode on the next call.\n "; +static char __pyx_doc_19dependency_injector_9providers_8Provider_24reset_async_mode[] = "Reset async mode.\n\n Provider will automatically set the mode on the next call.\n "; static PyObject *__pyx_pw_19dependency_injector_9providers_8Provider_25reset_async_mode(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations @@ -8227,7 +8325,7 @@ static PyObject *__pyx_pf_19dependency_injector_9providers_8Provider_24reset_asy __Pyx_RefNannySetupContext("reset_async_mode", 0); /* "dependency_injector/providers.pyx":318 - * Provider will automatically define the mode on the next call. + * Provider will automatically set the mode on the next call. * """ * self.__async_mode = ASYNC_MODE_UNDEFINED # <<<<<<<<<<<<<< * @@ -101279,7 +101377,9 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_dict1, __pyx_k_dict1, sizeof(__pyx_k_dict1), 0, 0, 1, 1}, {&__pyx_n_s_dict2, __pyx_k_dict2, sizeof(__pyx_k_dict2), 0, 0, 1, 1}, {&__pyx_n_s_dict_2, __pyx_k_dict_2, sizeof(__pyx_k_dict_2), 0, 0, 1, 1}, + {&__pyx_n_s_disable_async_mode, __pyx_k_disable_async_mode, sizeof(__pyx_k_disable_async_mode), 0, 0, 1, 1}, {&__pyx_n_s_doc, __pyx_k_doc, sizeof(__pyx_k_doc), 0, 0, 1, 1}, + {&__pyx_n_s_enable_async_mode, __pyx_k_enable_async_mode, sizeof(__pyx_k_enable_async_mode), 0, 0, 1, 1}, {&__pyx_n_s_endswith, __pyx_k_endswith, sizeof(__pyx_k_endswith), 0, 0, 1, 1}, {&__pyx_n_s_ensure_future, __pyx_k_ensure_future, sizeof(__pyx_k_ensure_future), 0, 0, 1, 1}, {&__pyx_n_s_enter, __pyx_k_enter, sizeof(__pyx_k_enter), 0, 0, 1, 1}, @@ -101319,6 +101419,9 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_instance, __pyx_k_instance, sizeof(__pyx_k_instance), 0, 0, 1, 1}, {&__pyx_n_s_instance_of, __pyx_k_instance_of, sizeof(__pyx_k_instance_of), 0, 0, 1, 1}, {&__pyx_n_s_interpolation, __pyx_k_interpolation, sizeof(__pyx_k_interpolation), 0, 0, 1, 1}, + {&__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}, diff --git a/src/dependency_injector/providers.pyx b/src/dependency_injector/providers.pyx index 00d3cde7..154e0e5c 100644 --- a/src/dependency_injector/providers.pyx +++ b/src/dependency_injector/providers.pyx @@ -167,19 +167,19 @@ cdef class Provider(object): else: result = self._provide(args, kwargs) - if self.__async_mode == ASYNC_MODE_DISABLED: + if self.is_async_mode_disabled(): return result - elif self.__async_mode == ASYNC_MODE_ENABLED: + elif self.is_async_mode_enabled(): if not __isawaitable(result): future_result = asyncio.Future() future_result.set_result(result) return future_result return result - elif self.__async_mode == ASYNC_MODE_UNDEFINED: + elif self.is_async_mode_undefined(): if __isawaitable(result): - self.__async_mode = ASYNC_MODE_ENABLED + self.enable_async_mode() else: - self.__async_mode = ASYNC_MODE_DISABLED + self.disable_async_mode() return result def __deepcopy__(self, memo): @@ -313,7 +313,7 @@ cdef class Provider(object): def reset_async_mode(self): """Reset async mode. - Provider will automatically define the mode on the next call. + Provider will automatically set the mode on the next call. """ self.__async_mode = ASYNC_MODE_UNDEFINED