modern-di 0.15.2__tar.gz → 0.16.1__tar.gz
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-0.15.2 → modern_di-0.16.1}/PKG-INFO +1 -1
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/container.py +2 -1
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/providers/abstract.py +15 -6
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/providers/dict.py +1 -1
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/providers/list.py +1 -1
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/providers/selector.py +1 -1
- {modern_di-0.15.2 → modern_di-0.16.1}/.gitignore +0 -0
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/__init__.py +0 -0
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/graph.py +0 -0
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/helpers/__init__.py +0 -0
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/helpers/attr_getter_helpers.py +0 -0
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/provider_state.py +0 -0
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/providers/__init__.py +0 -0
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/providers/async_factory.py +0 -0
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/providers/async_singleton.py +0 -0
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/providers/container_provider.py +0 -0
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/providers/context_adapter.py +0 -0
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/providers/factory.py +0 -0
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/providers/injected_factory.py +0 -0
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/providers/object.py +0 -0
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/providers/resource.py +0 -0
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/providers/singleton.py +0 -0
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/py.typed +0 -0
- {modern_di-0.15.2 → modern_di-0.16.1}/modern_di/scope.py +0 -0
- {modern_di-0.15.2 → modern_di-0.16.1}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: modern-di
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.16.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
|
|
@@ -4,6 +4,7 @@ import types
|
|
|
4
4
|
import typing
|
|
5
5
|
|
|
6
6
|
from modern_di.provider_state import ProviderState
|
|
7
|
+
from modern_di.scope import Scope
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
if typing.TYPE_CHECKING:
|
|
@@ -27,7 +28,7 @@ class Container(contextlib.AbstractAsyncContextManager["Container"], contextlib.
|
|
|
27
28
|
def __init__(
|
|
28
29
|
self,
|
|
29
30
|
*,
|
|
30
|
-
scope: enum.IntEnum,
|
|
31
|
+
scope: enum.IntEnum = Scope.APP,
|
|
31
32
|
parent_container: typing.Optional["Container"] = None,
|
|
32
33
|
context: dict[str, typing.Any] | None = None,
|
|
33
34
|
use_threading_lock: bool = True,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import abc
|
|
2
2
|
import enum
|
|
3
|
-
import itertools
|
|
4
3
|
import typing
|
|
5
4
|
import uuid
|
|
6
5
|
|
|
@@ -34,10 +33,20 @@ class AbstractProvider(typing.Generic[T_co], abc.ABC):
|
|
|
34
33
|
def cast(self) -> T_co:
|
|
35
34
|
return typing.cast(T_co, self)
|
|
36
35
|
|
|
37
|
-
def _check_providers_scope(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
def _check_providers_scope(
|
|
37
|
+
self, *, args: typing.Iterable[typing.Any] | None = None, kwargs: typing.Mapping[str, typing.Any] | None = None
|
|
38
|
+
) -> None:
|
|
39
|
+
if args:
|
|
40
|
+
for provider in args:
|
|
41
|
+
if isinstance(provider, AbstractProvider) and provider.scope > self.scope:
|
|
42
|
+
msg = f"Scope of dependency is {provider.scope.name} and current scope is {self.scope.name}"
|
|
43
|
+
raise RuntimeError(msg)
|
|
44
|
+
|
|
45
|
+
if kwargs:
|
|
46
|
+
for name, provider in kwargs.items():
|
|
47
|
+
if isinstance(provider, AbstractProvider) and provider.scope > self.scope:
|
|
48
|
+
msg = f"Scope of {name} is {provider.scope.name} and current scope is {self.scope.name}"
|
|
49
|
+
raise RuntimeError(msg)
|
|
41
50
|
|
|
42
51
|
def __getattr__(self, attr_name: str) -> typing.Any: # noqa: ANN401
|
|
43
52
|
"""Get an attribute from the resolve object.
|
|
@@ -75,7 +84,7 @@ class AbstractCreatorProvider(AbstractOverrideProvider[T_co], abc.ABC):
|
|
|
75
84
|
**kwargs: P.kwargs,
|
|
76
85
|
) -> None:
|
|
77
86
|
super().__init__(scope)
|
|
78
|
-
self._check_providers_scope(
|
|
87
|
+
self._check_providers_scope(args=args, kwargs=kwargs)
|
|
79
88
|
self._creator: typing.Final = creator
|
|
80
89
|
self._args: typing.Final = args
|
|
81
90
|
self._kwargs: typing.Final = kwargs
|
|
@@ -13,7 +13,7 @@ class Dict(AbstractProvider[dict[str, T_co]]):
|
|
|
13
13
|
|
|
14
14
|
def __init__(self, scope: enum.IntEnum, **providers: AbstractProvider[T_co]) -> None:
|
|
15
15
|
super().__init__(scope)
|
|
16
|
-
self._check_providers_scope(providers
|
|
16
|
+
self._check_providers_scope(kwargs=providers)
|
|
17
17
|
self._providers: typing.Final = providers
|
|
18
18
|
|
|
19
19
|
async def async_resolve(self, container: Container) -> dict[str, T_co]:
|
|
@@ -13,7 +13,7 @@ class List(AbstractProvider[list[T_co]]):
|
|
|
13
13
|
|
|
14
14
|
def __init__(self, scope: enum.IntEnum, *providers: AbstractProvider[T_co]) -> None:
|
|
15
15
|
super().__init__(scope)
|
|
16
|
-
self._check_providers_scope(providers)
|
|
16
|
+
self._check_providers_scope(args=providers)
|
|
17
17
|
self._providers: typing.Final = providers
|
|
18
18
|
|
|
19
19
|
async def async_resolve(self, container: Container) -> list[T_co]:
|
|
@@ -16,7 +16,7 @@ class Selector(AbstractProvider[T_co]):
|
|
|
16
16
|
self, scope: enum.IntEnum, function: typing.Callable[..., str], **providers: AbstractProvider[T_co]
|
|
17
17
|
) -> None:
|
|
18
18
|
super().__init__(scope)
|
|
19
|
-
self._check_providers_scope(providers
|
|
19
|
+
self._check_providers_scope(kwargs=providers)
|
|
20
20
|
self._function: typing.Final = function
|
|
21
21
|
self._providers: typing.Final = providers
|
|
22
22
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|