Skip to content

Commit 8cad8c6

Browse files
committed
Merge branch 'release/4.30.0' into master
2 parents ee89476 + 9ea8709 commit 8cad8c6

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

docs/main/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ that were made in every particular version.
77
From version 0.7.6 *Dependency Injector* framework strictly
88
follows `Semantic versioning`_
99

10+
4.30.0
11+
------
12+
- Remove restriction to wire a dynamic container.
13+
1014
4.29.2
1115
------
1216
- Fix wiring to not crash on missing signatures.

src/dependency_injector/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Top-level package."""
22

3-
__version__ = '4.29.2'
3+
__version__ = '4.30.0'
44
"""Version number.
55
66
:type: str

src/dependency_injector/wiring.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,6 @@ def wire( # noqa: C901
322322
packages: Optional[Iterable[ModuleType]] = None,
323323
) -> None:
324324
"""Wire container providers with provided packages and modules."""
325-
if not _is_declarative_container_instance(container):
326-
raise Exception('Can wire only an instance of the declarative container')
327-
328325
if not modules:
329326
modules = []
330327

@@ -655,12 +652,6 @@ def _is_patched(fn):
655652
return getattr(fn, '__wired__', False) is True
656653

657654

658-
def _is_declarative_container_instance(instance: Any) -> bool:
659-
return (not isinstance(instance, type)
660-
and getattr(instance, '__IS_CONTAINER__', False) is True
661-
and getattr(instance, 'declarative_parent', None) is not None)
662-
663-
664655
def _is_declarative_container(instance: Any) -> bool:
665656
return (isinstance(instance, type)
666657
and getattr(instance, '__IS_CONTAINER__', False) is True

tests/unit/wiring/test_wiring_string_ids_py36.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Provider,
88
Closing,
99
)
10-
from dependency_injector import errors
10+
from dependency_injector import containers, providers, errors
1111

1212
# Runtime import to avoid syntax errors in samples on Python < 3.5
1313
import os
@@ -335,6 +335,27 @@ def test_closing_resource_bypass_marker_injection(self):
335335
self.assertIsNot(result_1, result_2)
336336

337337

338+
class WireDynamicContainerTest(unittest.TestCase):
339+
340+
def test_wire(self):
341+
sub = containers.DynamicContainer()
342+
sub.int_object = providers.Object(1)
343+
344+
container = containers.DynamicContainer()
345+
container.config = providers.Configuration()
346+
container.service = providers.Factory(Service)
347+
container.sub = sub
348+
349+
container.wire(
350+
modules=[module],
351+
packages=[package],
352+
)
353+
self.addCleanup(container.unwire)
354+
355+
service = module.test_function()
356+
self.assertIsInstance(service, Service)
357+
358+
338359
class WiringAsyncInjectionsTest(AsyncTestCase):
339360

340361
def test_async_injections(self):

0 commit comments

Comments
 (0)