mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 01:26:51 +03:00
Refactor async mode support in containers module
This commit is contained in:
parent
18051522d7
commit
c7ba58c0af
|
@ -7,6 +7,10 @@ that were made in every particular version.
|
||||||
From version 0.7.6 *Dependency Injector* framework strictly
|
From version 0.7.6 *Dependency Injector* framework strictly
|
||||||
follows `Semantic versioning`_
|
follows `Semantic versioning`_
|
||||||
|
|
||||||
|
Development version
|
||||||
|
-------------------
|
||||||
|
- Refactor async mode support in containers module.
|
||||||
|
|
||||||
4.23.5
|
4.23.5
|
||||||
------
|
------
|
||||||
- Fix docs publishing.
|
- Fix docs publishing.
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -11,6 +11,3 @@ cpdef bint is_container(object instance)
|
||||||
|
|
||||||
|
|
||||||
cpdef object _check_provider_type(object container, object provider)
|
cpdef object _check_provider_type(object container, object provider)
|
||||||
|
|
||||||
|
|
||||||
cpdef bint _isawaitable(object instance)
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"""Containers module."""
|
"""Containers module."""
|
||||||
|
|
||||||
import inspect
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -11,6 +10,7 @@ except ImportError:
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from . import providers, errors
|
from . import providers, errors
|
||||||
|
from .providers cimport __is_future_or_coroutine
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info[:2] >= (3, 6):
|
if sys.version_info[:2] >= (3, 6):
|
||||||
|
@ -276,7 +276,7 @@ class DynamicContainer(Container):
|
||||||
for provider in self.traverse(types=[providers.Resource]):
|
for provider in self.traverse(types=[providers.Resource]):
|
||||||
resource = provider.init()
|
resource = provider.init()
|
||||||
|
|
||||||
if _isawaitable(resource):
|
if __is_future_or_coroutine(resource):
|
||||||
futures.append(resource)
|
futures.append(resource)
|
||||||
|
|
||||||
if futures:
|
if futures:
|
||||||
|
@ -289,7 +289,7 @@ class DynamicContainer(Container):
|
||||||
for provider in self.traverse(types=[providers.Resource]):
|
for provider in self.traverse(types=[providers.Resource]):
|
||||||
shutdown = provider.shutdown()
|
shutdown = provider.shutdown()
|
||||||
|
|
||||||
if _isawaitable(shutdown):
|
if __is_future_or_coroutine(shutdown):
|
||||||
futures.append(shutdown)
|
futures.append(shutdown)
|
||||||
|
|
||||||
if futures:
|
if futures:
|
||||||
|
@ -711,10 +711,3 @@ cpdef object _check_provider_type(object container, object provider):
|
||||||
if not isinstance(provider, container.provider_type):
|
if not isinstance(provider, container.provider_type):
|
||||||
raise errors.Error('{0} can contain only {1} '
|
raise errors.Error('{0} can contain only {1} '
|
||||||
'instances'.format(container, container.provider_type))
|
'instances'.format(container, container.provider_type))
|
||||||
|
|
||||||
|
|
||||||
cpdef bint _isawaitable(object instance):
|
|
||||||
try:
|
|
||||||
return <bint> inspect.isawaitable(instance)
|
|
||||||
except AttributeError:
|
|
||||||
return <bint> False
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user