modern-di 0.14.0__tar.gz → 0.15.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.

Files changed (25) hide show
  1. {modern_di-0.14.0 → modern_di-0.15.1}/PKG-INFO +1 -1
  2. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/container.py +4 -0
  3. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/providers/__init__.py +2 -0
  4. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/providers/async_factory.py +1 -1
  5. modern_di-0.15.1/modern_di/providers/async_singleton.py +49 -0
  6. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/providers/factory.py +1 -1
  7. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/providers/resource.py +2 -2
  8. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/providers/singleton.py +1 -1
  9. {modern_di-0.14.0 → modern_di-0.15.1}/.gitignore +0 -0
  10. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/__init__.py +0 -0
  11. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/graph.py +0 -0
  12. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/helpers/__init__.py +0 -0
  13. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/helpers/attr_getter_helpers.py +0 -0
  14. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/provider_state.py +0 -0
  15. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/providers/abstract.py +0 -0
  16. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/providers/container_provider.py +0 -0
  17. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/providers/context_adapter.py +0 -0
  18. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/providers/dict.py +0 -0
  19. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/providers/injected_factory.py +0 -0
  20. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/providers/list.py +0 -0
  21. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/providers/object.py +0 -0
  22. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/providers/selector.py +0 -0
  23. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/py.typed +0 -0
  24. {modern_di-0.14.0 → modern_di-0.15.1}/modern_di/scope.py +0 -0
  25. {modern_di-0.14.0 → modern_di-0.15.1}/pyproject.toml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: modern-di
3
- Version: 0.14.0
3
+ Version: 0.15.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
@@ -160,3 +160,7 @@ class Container(contextlib.AbstractAsyncContextManager["Container"], contextlib.
160
160
  traceback: types.TracebackType | None,
161
161
  ) -> None:
162
162
  self.sync_close()
163
+
164
+ def __deepcopy__(self, *_: object, **__: object) -> "typing_extensions.Self":
165
+ """Hack for FastStream to prevent cloning object."""
166
+ return self
@@ -1,5 +1,6 @@
1
1
  from modern_di.providers.abstract import AbstractProvider
2
2
  from modern_di.providers.async_factory import AsyncFactory
3
+ from modern_di.providers.async_singleton import AsyncSingleton
3
4
  from modern_di.providers.container_provider import ContainerProvider
4
5
  from modern_di.providers.context_adapter import ContextAdapter
5
6
  from modern_di.providers.dict import Dict
@@ -14,6 +15,7 @@ from modern_di.providers.singleton import Singleton
14
15
  __all__ = [
15
16
  "AbstractProvider",
16
17
  "AsyncFactory",
18
+ "AsyncSingleton",
17
19
  "ContainerProvider",
18
20
  "ContextAdapter",
19
21
  "Dict",
@@ -10,7 +10,7 @@ P = typing.ParamSpec("P")
10
10
 
11
11
 
12
12
  class AsyncFactory(AbstractCreatorProvider[T_co]):
13
- __slots__ = [*AbstractCreatorProvider.BASE_SLOTS, "_creator"]
13
+ __slots__ = AbstractCreatorProvider.BASE_SLOTS
14
14
 
15
15
  def __init__(
16
16
  self,
@@ -0,0 +1,49 @@
1
+ import enum
2
+ import typing
3
+
4
+ from modern_di import Container
5
+ from modern_di.providers.abstract import AbstractCreatorProvider
6
+
7
+
8
+ T_co = typing.TypeVar("T_co", covariant=True)
9
+ P = typing.ParamSpec("P")
10
+
11
+
12
+ class AsyncSingleton(AbstractCreatorProvider[T_co]):
13
+ __slots__ = AbstractCreatorProvider.BASE_SLOTS
14
+
15
+ def __init__(
16
+ self,
17
+ scope: enum.IntEnum,
18
+ creator: typing.Callable[P, typing.Awaitable[T_co]],
19
+ *args: P.args,
20
+ **kwargs: P.kwargs,
21
+ ) -> None:
22
+ super().__init__(scope, creator, *args, **kwargs)
23
+
24
+ async def async_resolve(self, container: Container) -> T_co:
25
+ container = container.find_container(self.scope)
26
+ if (override := container.fetch_override(self.provider_id)) is not None:
27
+ return typing.cast(T_co, override)
28
+
29
+ provider_state = container.fetch_provider_state(self.provider_id, use_asyncio_lock=True)
30
+ if provider_state.instance is not None:
31
+ return typing.cast(T_co, provider_state.instance)
32
+
33
+ assert provider_state.asyncio_lock
34
+ await provider_state.asyncio_lock.acquire()
35
+
36
+ try:
37
+ if provider_state.instance is not None:
38
+ return typing.cast(T_co, provider_state.instance)
39
+
40
+ coroutine: typing.Awaitable[T_co] = await self._async_build_creator(container)
41
+ provider_state.instance = await coroutine
42
+ finally:
43
+ provider_state.asyncio_lock.release()
44
+
45
+ return provider_state.instance
46
+
47
+ def sync_resolve(self, _: Container) -> typing.NoReturn:
48
+ msg = "AsyncSingleton cannot be resolved synchronously"
49
+ raise RuntimeError(msg)
@@ -11,7 +11,7 @@ P = typing.ParamSpec("P")
11
11
 
12
12
 
13
13
  class Factory(AbstractCreatorProvider[T_co]):
14
- __slots__ = [*AbstractCreatorProvider.BASE_SLOTS, "_creator"]
14
+ __slots__ = AbstractCreatorProvider.BASE_SLOTS
15
15
 
16
16
  def __init__(
17
17
  self,
@@ -1,4 +1,4 @@
1
- import contextlib # noqa: A005
1
+ import contextlib
2
2
  import enum
3
3
  import inspect
4
4
  import typing
@@ -12,7 +12,7 @@ P = typing.ParamSpec("P")
12
12
 
13
13
 
14
14
  class Resource(AbstractCreatorProvider[T_co]):
15
- __slots__ = [*AbstractCreatorProvider.BASE_SLOTS, "_creator", "_args", "_kwargs", "_is_async"]
15
+ __slots__ = [*AbstractCreatorProvider.BASE_SLOTS, "_is_async"]
16
16
 
17
17
  def _is_creator_async(
18
18
  self,
@@ -10,7 +10,7 @@ P = typing.ParamSpec("P")
10
10
 
11
11
 
12
12
  class Singleton(AbstractCreatorProvider[T_co]):
13
- __slots__ = [*AbstractCreatorProvider.BASE_SLOTS, "_creator"]
13
+ __slots__ = AbstractCreatorProvider.BASE_SLOTS
14
14
 
15
15
  def __init__(
16
16
  self,
File without changes
File without changes