modern-di 0.4.3__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 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 {}
@@ -45,16 +41,22 @@ class Container(contextlib.AbstractAsyncContextManager["Container"]):
45
41
  msg = "Enter the context first"
46
42
  raise RuntimeError(msg)
47
43
 
48
- def build_child_container(self, context: dict[str, typing.Any] | None = None) -> "typing_extensions.Self":
44
+ def build_child_container(
45
+ self, context: dict[str, typing.Any] | None = None, scope: enum.IntEnum | None = None
46
+ ) -> "typing_extensions.Self":
49
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)
50
51
 
51
- try:
52
- new_scope = self.scope.__class__(self.scope.value + 1)
53
- except ValueError as exc:
54
- msg = f"Max scope is reached, {self.scope.name}"
55
- raise RuntimeError(msg) from exc
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
56
58
 
57
- return self.__class__(scope=new_scope, parent_container=self, context=context)
59
+ return self.__class__(scope=scope, parent_container=self, context=context)
58
60
 
59
61
  def find_container(self, scope: enum.IntEnum) -> "typing_extensions.Self":
60
62
  container = self
@@ -64,6 +66,11 @@ class Container(contextlib.AbstractAsyncContextManager["Container"]):
64
66
 
65
67
  while container.scope > scope and container.parent_container:
66
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
+
67
74
  return container
68
75
 
69
76
  def fetch_provider_state(
modern_di/scope.py CHANGED
@@ -3,6 +3,7 @@ import enum
3
3
 
4
4
  class Scope(enum.IntEnum):
5
5
  APP = 1
6
- REQUEST = 2
7
- ACTION = 3
8
- STEP = 4
6
+ SESSION = 2
7
+ REQUEST = 3
8
+ ACTION = 4
9
+ STEP = 5
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: modern-di
3
- Version: 0.4.3
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=v96v5qPTGfYaONuMZhO-C4K7rMlCfzLzZdCLuJtviCw,4156
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=nnrTLnFT_dMDLVIwvJHcGlJsB2k1WIHusrRSGQIMEsg,97
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.4.3.dist-info/METADATA,sha256=s6Q1DeZMxAAuAs8ce9wGcYd4DRbLZCWPGJBpAtQaslk,2767
17
- modern_di-0.4.3.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
18
- modern_di-0.4.3.dist-info/licenses/LICENSE,sha256=aA5_eJwDKqnGvL7PbkPb9x5f-VGIqZ9cvWWkeGqeD90,1070
19
- modern_di-0.4.3.dist-info/RECORD,,
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,,