modern-di 0.14.0__py3-none-any.whl → 0.15.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/providers/__init__.py +2 -0
- modern_di/providers/async_singleton.py +49 -0
- modern_di/providers/resource.py +1 -1
- {modern_di-0.14.0.dist-info → modern_di-0.15.0.dist-info}/METADATA +1 -1
- {modern_di-0.14.0.dist-info → modern_di-0.15.0.dist-info}/RECORD +6 -5
- {modern_di-0.14.0.dist-info → modern_di-0.15.0.dist-info}/WHEEL +0 -0
modern_di/providers/__init__.py
CHANGED
|
@@ -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",
|
|
@@ -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, "_creator"]
|
|
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)
|
modern_di/providers/resource.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: modern-di
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.15.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
|
|
@@ -6,9 +6,10 @@ modern_di/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
6
6
|
modern_di/scope.py,sha256=e6Olc-CF89clbYDNGciy-F8EqJt1Mw2703zfuJaEY94,113
|
|
7
7
|
modern_di/helpers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
8
|
modern_di/helpers/attr_getter_helpers.py,sha256=HUjExWLRAz2h0YX2_h5xKPX9-_K3i-BZTeZb3u-Wq5k,221
|
|
9
|
-
modern_di/providers/__init__.py,sha256=
|
|
9
|
+
modern_di/providers/__init__.py,sha256=u19TXXMG0Ex8YsAnLzsf2mz3K78zEFVLBT_SiD51Dyw,873
|
|
10
10
|
modern_di/providers/abstract.py,sha256=TZryLsWRXsOu0aApmY13iHTNHTl1yU7jHs6sPCJrz5k,5417
|
|
11
11
|
modern_di/providers/async_factory.py,sha256=KTsUL5S-Pz0VGPdjle9qhdMs9QD_B39ifjhSqiWgStY,1090
|
|
12
|
+
modern_di/providers/async_singleton.py,sha256=DPdVWuIBvjrtNeweUxPD5SY9h97W_tFUTP_jVwmjxxU,1664
|
|
12
13
|
modern_di/providers/container_provider.py,sha256=r5IEQXgKtPwvHvbqkbPnmGyDGGCCjokTtdard9Rvt40,548
|
|
13
14
|
modern_di/providers/context_adapter.py,sha256=_b1x3ToQPWT-9KkDioFhw1W8Q1VXZYUnczfYzMTobVA,760
|
|
14
15
|
modern_di/providers/dict.py,sha256=nCU9iaqteYHDbILAfhrdnbMgS9_emE4MS7Xn2VoUlPo,858
|
|
@@ -16,9 +17,9 @@ modern_di/providers/factory.py,sha256=Nn9WZuOHF4r5Go4vOuW_jAjmXs0A2WJCGiGQ1eUFB5
|
|
|
16
17
|
modern_di/providers/injected_factory.py,sha256=KkDww-zUgm41LFt5j8crRzzFuBSkmKvOfptzHWMgVok,1848
|
|
17
18
|
modern_di/providers/list.py,sha256=3hx34RfBRmqzh-cT5D6wSTDJPkBGMK_ul4n9gQz-o9M,769
|
|
18
19
|
modern_di/providers/object.py,sha256=Sm0mb3Ua7cZ5Ay65fLvl7fnJDSQrQZwvzio3lkkXP2A,825
|
|
19
|
-
modern_di/providers/resource.py,sha256=
|
|
20
|
+
modern_di/providers/resource.py,sha256=CsMekkVISklTqN539XqH4iE80vfc6sQMav5OT8fZvyA,4591
|
|
20
21
|
modern_di/providers/selector.py,sha256=RQbHD2-Liw-TGqu6UELbfCzXYuqxiO_Mg1tLyF3mKQo,1419
|
|
21
22
|
modern_di/providers/singleton.py,sha256=_hUpCmbHgLAigdhBiu0zypwWwrIGdB6_oZkGfuLxzNE,2372
|
|
22
|
-
modern_di-0.
|
|
23
|
-
modern_di-0.
|
|
24
|
-
modern_di-0.
|
|
23
|
+
modern_di-0.15.0.dist-info/METADATA,sha256=KiiRM95AvmML0q-oqC5SSz1JAHJB4HFMmXNr-yjKVPY,3382
|
|
24
|
+
modern_di-0.15.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
25
|
+
modern_di-0.15.0.dist-info/RECORD,,
|
|
File without changes
|