modern-di 0.4.3__py3-none-any.whl → 0.5.1__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,13 +1,12 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: modern-di
3
- Version: 0.4.3
3
+ Version: 0.5.1
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
7
7
  Author-email: Artur Shiriev <me@shiriev.ru>
8
8
  License-Expression: MIT
9
- License-File: LICENSE
10
- Keywords: dependency injector,di,ioc-container,mocks,python
9
+ Keywords: DI,dependency injector,ioc-container,mocks,python
11
10
  Classifier: Programming Language :: Python :: 3.10
12
11
  Classifier: Programming Language :: Python :: 3.11
13
12
  Classifier: Programming Language :: Python :: 3.12
@@ -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,6 @@ 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.1.dist-info/METADATA,sha256=RrhmXaaNkHk5qyOfqclWkC39M2zMtOC4ADmAhr1EhCs,2745
17
+ modern_di-0.5.1.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
18
+ modern_di-0.5.1.dist-info/RECORD,,
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 modern-python
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.