Refactor async mode support in containers module

This commit is contained in:
Roman Mogylatov 2021-02-18 08:17:05 -05:00
parent 18051522d7
commit c7ba58c0af
4 changed files with 8416 additions and 609 deletions

View File

@ -7,6 +7,10 @@ that were made in every particular version.
From version 0.7.6 *Dependency Injector* framework strictly
follows `Semantic versioning`_
Development version
-------------------
- Refactor async mode support in containers module.
4.23.5
------
- Fix docs publishing.

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,3 @@ cpdef bint is_container(object instance)
cpdef object _check_provider_type(object container, object provider)
cpdef bint _isawaitable(object instance)

View File

@ -1,6 +1,5 @@
"""Containers module."""
import inspect
import sys
try:
@ -11,6 +10,7 @@ except ImportError:
import six
from . import providers, errors
from .providers cimport __is_future_or_coroutine
if sys.version_info[:2] >= (3, 6):
@ -276,7 +276,7 @@ class DynamicContainer(Container):
for provider in self.traverse(types=[providers.Resource]):
resource = provider.init()
if _isawaitable(resource):
if __is_future_or_coroutine(resource):
futures.append(resource)
if futures:
@ -289,7 +289,7 @@ class DynamicContainer(Container):
for provider in self.traverse(types=[providers.Resource]):
shutdown = provider.shutdown()
if _isawaitable(shutdown):
if __is_future_or_coroutine(shutdown):
futures.append(shutdown)
if futures:
@ -711,10 +711,3 @@ cpdef object _check_provider_type(object container, object provider):
if not isinstance(provider, container.provider_type):
raise errors.Error('{0} can contain only {1} '
'instances'.format(container, container.provider_type))
cpdef bint _isawaitable(object instance):
try:
return <bint> inspect.isawaitable(instance)
except AttributeError:
return <bint> False