Merge branch 'release/4.30.0' into master

This commit is contained in:
Roman Mogylatov 2021-03-19 20:23:39 -04:00
commit 8cad8c6b65
4 changed files with 27 additions and 11 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`_
4.30.0
------
- Remove restriction to wire a dynamic container.
4.29.2
------
- Fix wiring to not crash on missing signatures.

View File

@ -1,6 +1,6 @@
"""Top-level package."""
__version__ = '4.29.2'
__version__ = '4.30.0'
"""Version number.
:type: str

View File

@ -322,9 +322,6 @@ def wire( # noqa: C901
packages: Optional[Iterable[ModuleType]] = None,
) -> None:
"""Wire container providers with provided packages and modules."""
if not _is_declarative_container_instance(container):
raise Exception('Can wire only an instance of the declarative container')
if not modules:
modules = []
@ -655,12 +652,6 @@ def _is_patched(fn):
return getattr(fn, '__wired__', False) is True
def _is_declarative_container_instance(instance: Any) -> bool:
return (not isinstance(instance, type)
and getattr(instance, '__IS_CONTAINER__', False) is True
and getattr(instance, 'declarative_parent', None) is not None)
def _is_declarative_container(instance: Any) -> bool:
return (isinstance(instance, type)
and getattr(instance, '__IS_CONTAINER__', False) is True

View File

@ -7,7 +7,7 @@ from dependency_injector.wiring import (
Provider,
Closing,
)
from dependency_injector import errors
from dependency_injector import containers, providers, errors
# Runtime import to avoid syntax errors in samples on Python < 3.5
import os
@ -335,6 +335,27 @@ class WiringAndFastAPITest(unittest.TestCase):
self.assertIsNot(result_1, result_2)
class WireDynamicContainerTest(unittest.TestCase):
def test_wire(self):
sub = containers.DynamicContainer()
sub.int_object = providers.Object(1)
container = containers.DynamicContainer()
container.config = providers.Configuration()
container.service = providers.Factory(Service)
container.sub = sub
container.wire(
modules=[module],
packages=[package],
)
self.addCleanup(container.unwire)
service = module.test_function()
self.assertIsInstance(service, Service)
class WiringAsyncInjectionsTest(AsyncTestCase):
def test_async_injections(self):