modern-di 0.4.2__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of modern-di might be problematic. Click here for more details.
- modern_di/container.py +23 -11
- modern_di/scope.py +4 -3
- {modern_di-0.4.2.dist-info → modern_di-0.5.0.dist-info}/METADATA +1 -1
- {modern_di-0.4.2.dist-info → modern_di-0.5.0.dist-info}/RECORD +6 -6
- {modern_di-0.4.2.dist-info → modern_di-0.5.0.dist-info}/WHEEL +0 -0
- {modern_di-0.4.2.dist-info → modern_di-0.5.0.dist-info}/licenses/LICENSE +0 -0
modern_di/container.py
CHANGED
|
@@ -23,10 +23,6 @@ class Container(contextlib.AbstractAsyncContextManager["Container"]):
|
|
|
23
23
|
parent_container: typing.Optional["Container"] = None,
|
|
24
24
|
context: dict[str, typing.Any] | None = None,
|
|
25
25
|
) -> None:
|
|
26
|
-
if scope.value != 1 and parent_container is None:
|
|
27
|
-
msg = "Only first scope can be used without parent_container"
|
|
28
|
-
raise RuntimeError(msg)
|
|
29
|
-
|
|
30
26
|
self.scope = scope
|
|
31
27
|
self.parent_container = parent_container
|
|
32
28
|
self.context: dict[str, typing.Any] = context or {}
|
|
@@ -38,27 +34,43 @@ class Container(contextlib.AbstractAsyncContextManager["Container"]):
|
|
|
38
34
|
self._is_async = None
|
|
39
35
|
self._provider_states = {}
|
|
40
36
|
self._overrides = {}
|
|
37
|
+
self.context = {}
|
|
41
38
|
|
|
42
39
|
def _check_entered(self) -> None:
|
|
43
40
|
if self._is_async is None:
|
|
44
41
|
msg = "Enter the context first"
|
|
45
42
|
raise RuntimeError(msg)
|
|
46
43
|
|
|
47
|
-
def build_child_container(
|
|
44
|
+
def build_child_container(
|
|
45
|
+
self, context: dict[str, typing.Any] | None = None, scope: enum.IntEnum | None = None
|
|
46
|
+
) -> "typing_extensions.Self":
|
|
48
47
|
self._check_entered()
|
|
48
|
+
if scope and scope <= self.scope:
|
|
49
|
+
msg = "Scope of child container must be more than current scope"
|
|
50
|
+
raise RuntimeError(msg)
|
|
49
51
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
if not scope:
|
|
53
|
+
try:
|
|
54
|
+
scope = self.scope.__class__(self.scope.value + 1)
|
|
55
|
+
except ValueError as exc:
|
|
56
|
+
msg = f"Max scope is reached, {self.scope.name}"
|
|
57
|
+
raise RuntimeError(msg) from exc
|
|
55
58
|
|
|
56
|
-
return self.__class__(scope=
|
|
59
|
+
return self.__class__(scope=scope, parent_container=self, context=context)
|
|
57
60
|
|
|
58
61
|
def find_container(self, scope: enum.IntEnum) -> "typing_extensions.Self":
|
|
59
62
|
container = self
|
|
63
|
+
if container.scope < scope:
|
|
64
|
+
msg = f"Scope {scope.name} is not initialized"
|
|
65
|
+
raise RuntimeError(msg)
|
|
66
|
+
|
|
60
67
|
while container.scope > scope and container.parent_container:
|
|
61
68
|
container = typing.cast("typing_extensions.Self", container.parent_container)
|
|
69
|
+
|
|
70
|
+
if container.scope != scope:
|
|
71
|
+
msg = f"Scope {scope.name} is skipped"
|
|
72
|
+
raise RuntimeError(msg)
|
|
73
|
+
|
|
62
74
|
return container
|
|
63
75
|
|
|
64
76
|
def fetch_provider_state(
|
modern_di/scope.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: modern-di
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Dependency Injection framework with IOC-container and scopes
|
|
5
5
|
Project-URL: repository, https://github.com/modern-python/modern-di
|
|
6
6
|
Project-URL: docs, https://modern-di.readthedocs.io
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
modern_di/__init__.py,sha256=L01VkzSJiV0d0FPrh1DZ-Wy5mUmoG6X-oLz7xYxtehI,194
|
|
2
|
-
modern_di/container.py,sha256=
|
|
2
|
+
modern_di/container.py,sha256=wJ18aOVb-RMFEBafTesZdvMUOSlJ-44qcNFtR0Cak1Q,4351
|
|
3
3
|
modern_di/graph.py,sha256=X60wtG3Mqus_5YZNiZlQuXoHODBp7rYl_IHJs7GzSQM,1356
|
|
4
4
|
modern_di/provider_state.py,sha256=5Bl_iYEpXjMqoWZJ4op2-axo4Z8nR_vYbLVHL_u5R0c,1206
|
|
5
5
|
modern_di/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
modern_di/scope.py,sha256=
|
|
6
|
+
modern_di/scope.py,sha256=e6Olc-CF89clbYDNGciy-F8EqJt1Mw2703zfuJaEY94,113
|
|
7
7
|
modern_di/providers/__init__.py,sha256=oeP3sKZJQF9COfT_YYJiLwiU3CbDfQMk4rzYHO52Xvg,555
|
|
8
8
|
modern_di/providers/abstract.py,sha256=UMj4CRn-JfGZfiveWFTkH7V92h4UXS4eYf8noZqPWGQ,3107
|
|
9
9
|
modern_di/providers/context_adapter.py,sha256=_b1x3ToQPWT-9KkDioFhw1W8Q1VXZYUnczfYzMTobVA,760
|
|
@@ -13,7 +13,7 @@ modern_di/providers/list.py,sha256=3hx34RfBRmqzh-cT5D6wSTDJPkBGMK_ul4n9gQz-o9M,7
|
|
|
13
13
|
modern_di/providers/resource.py,sha256=nKy8_Wfn2cAIvlu_qGjGanmlgrkHQUsZxBNNR6p7OuE,3649
|
|
14
14
|
modern_di/providers/selector.py,sha256=RQbHD2-Liw-TGqu6UELbfCzXYuqxiO_Mg1tLyF3mKQo,1419
|
|
15
15
|
modern_di/providers/singleton.py,sha256=7XBNhVzhV5Rh_F7iWZx8is7i7_PuctQ9thKeqIkjnTs,1999
|
|
16
|
-
modern_di-0.
|
|
17
|
-
modern_di-0.
|
|
18
|
-
modern_di-0.
|
|
19
|
-
modern_di-0.
|
|
16
|
+
modern_di-0.5.0.dist-info/METADATA,sha256=X9pp9celMjvLs1YG9_Lpoma9trQ6bnjGm7B2xlR0_kU,2767
|
|
17
|
+
modern_di-0.5.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
18
|
+
modern_di-0.5.0.dist-info/licenses/LICENSE,sha256=aA5_eJwDKqnGvL7PbkPb9x5f-VGIqZ9cvWWkeGqeD90,1070
|
|
19
|
+
modern_di-0.5.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|