mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-07-04 20:33:13 +03:00
Fix tests
This commit is contained in:
parent
d50fbbd83b
commit
c4825956f7
File diff suppressed because it is too large
Load Diff
|
@ -2712,8 +2712,9 @@ cdef class Resource(Provider):
|
||||||
shutdown = self.__shutdowner(self.__resource)
|
shutdown = self.__shutdowner(self.__resource)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
pass
|
pass
|
||||||
if inspect.isawaitable(shutdown):
|
else:
|
||||||
return __async_resource_shutdown(self, shutdown)
|
if inspect.isawaitable(shutdown):
|
||||||
|
return __async_resource_shutdown(self, shutdown)
|
||||||
|
|
||||||
self.__resource = None
|
self.__resource = None
|
||||||
self.__initialized = False
|
self.__initialized = False
|
||||||
|
@ -2760,7 +2761,7 @@ cdef class Resource(Provider):
|
||||||
)
|
)
|
||||||
self.__resource = next(initializer)
|
self.__resource = next(initializer)
|
||||||
self.__shutdowner = initializer.send
|
self.__shutdowner = initializer.send
|
||||||
elif inspect.iscoroutinefunction(self.__initializer):
|
elif iscoroutinefunction(self.__initializer):
|
||||||
initializer = __call(
|
initializer = __call(
|
||||||
self.__initializer,
|
self.__initializer,
|
||||||
args,
|
args,
|
||||||
|
@ -2772,7 +2773,7 @@ cdef class Resource(Provider):
|
||||||
)
|
)
|
||||||
self.__initialized = True
|
self.__initialized = True
|
||||||
return __async_resource_init(self, initializer)
|
return __async_resource_init(self, initializer)
|
||||||
elif inspect.isasyncgenfunction(self.__initializer):
|
elif isasyncgenfunction(self.__initializer):
|
||||||
initializer = __call(
|
initializer = __call(
|
||||||
self.__initializer,
|
self.__initializer,
|
||||||
args,
|
args,
|
||||||
|
@ -3431,6 +3432,26 @@ def merge_dicts(dict1, dict2):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def iscoroutinefunction(obj):
|
||||||
|
"""Check if object is a coroutine function.
|
||||||
|
Return False for any object in Python 3.4 or below.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return inspect.iscoroutinefunction(obj)
|
||||||
|
except AttributeError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def isasyncgenfunction(obj):
|
||||||
|
"""Check if object is an asynchronous generator function.
|
||||||
|
Return False for any object in Python 3.4 or below.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return inspect.isasyncgenfunction(obj)
|
||||||
|
except AttributeError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def __async_resource_init(self: Resource, initializer: object, shutdowner: object = None) -> None:
|
async def __async_resource_init(self: Resource, initializer: object, shutdowner: object = None) -> None:
|
||||||
try:
|
try:
|
||||||
resource = await initializer
|
resource = await initializer
|
||||||
|
|
Loading…
Reference in New Issue
Block a user