python-injection 0.11.0__py3-none-any.whl → 0.12.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.
- injection/__init__.py +8 -9
- injection/__init__.pyi +48 -13
- injection/_core/__init__.py +1 -1
- injection/_core/common/asynchronous.py +49 -0
- injection/_core/common/invertible.py +3 -4
- injection/_core/common/lazy.py +0 -5
- injection/_core/common/type.py +2 -5
- injection/_core/descriptors.py +3 -3
- injection/_core/hook.py +13 -10
- injection/_core/injectables.py +98 -0
- injection/_core/module.py +246 -165
- injection/integrations/fastapi.py +17 -12
- injection/testing/__init__.pyi +1 -1
- {python_injection-0.11.0.dist-info → python_injection-0.12.1.dist-info}/METADATA +9 -12
- python_injection-0.12.1.dist-info/RECORD +24 -0
- {python_injection-0.11.0.dist-info → python_injection-0.12.1.dist-info}/WHEEL +1 -1
- injection/integrations/blacksheep.py +0 -34
- python_injection-0.11.0.dist-info/RECORD +0 -23
@@ -1,4 +1,4 @@
|
|
1
|
-
from collections.abc import
|
1
|
+
from collections.abc import Awaitable
|
2
2
|
from types import GenericAlias
|
3
3
|
from typing import Any, TypeAliasType
|
4
4
|
|
@@ -28,18 +28,29 @@ def Inject[T]( # noqa: N802
|
|
28
28
|
|
29
29
|
|
30
30
|
class InjectionDependency[T]:
|
31
|
-
__slots__ = ("
|
31
|
+
__slots__ = ("__class", "__lazy_instance", "__module")
|
32
32
|
|
33
|
-
__call__: Callable[[], T]
|
34
33
|
__class: type[T] | TypeAliasType | GenericAlias
|
34
|
+
__lazy_instance: Awaitable[T]
|
35
35
|
__module: Module
|
36
36
|
|
37
|
-
def __init__(
|
38
|
-
|
39
|
-
|
37
|
+
def __init__(
|
38
|
+
self,
|
39
|
+
cls: type[T] | TypeAliasType | GenericAlias,
|
40
|
+
module: Module,
|
41
|
+
) -> None:
|
40
42
|
self.__class = cls
|
43
|
+
self.__lazy_instance = module.aget_lazy_instance(cls, default=NotImplemented)
|
41
44
|
self.__module = module
|
42
45
|
|
46
|
+
async def __call__(self) -> T:
|
47
|
+
instance = await self.__lazy_instance
|
48
|
+
|
49
|
+
if instance is NotImplemented:
|
50
|
+
raise InjectionError(f"`{self.__class}` is an unknown dependency.")
|
51
|
+
|
52
|
+
return instance
|
53
|
+
|
43
54
|
def __eq__(self, other: Any) -> bool:
|
44
55
|
if isinstance(other, type(self)):
|
45
56
|
return self.__key == other.__key
|
@@ -52,9 +63,3 @@ class InjectionDependency[T]:
|
|
52
63
|
@property
|
53
64
|
def __key(self) -> tuple[type[T] | TypeAliasType | GenericAlias, Module]:
|
54
65
|
return self.__class, self.__module
|
55
|
-
|
56
|
-
def __ensure(self, instance: T) -> T:
|
57
|
-
if instance is NotImplemented:
|
58
|
-
raise InjectionError(f"`{self.__class}` is an unknown dependency.")
|
59
|
-
|
60
|
-
return instance
|
injection/testing/__init__.pyi
CHANGED
@@ -8,7 +8,7 @@ test_constant = _.constant
|
|
8
8
|
test_injectable = _.injectable
|
9
9
|
test_singleton = _.singleton
|
10
10
|
|
11
|
-
def load_test_profile(*
|
11
|
+
def load_test_profile(*names: str) -> ContextManager[None]:
|
12
12
|
"""
|
13
13
|
Context manager or decorator for temporary use test module.
|
14
14
|
"""
|
@@ -1,26 +1,23 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.3
|
2
2
|
Name: python-injection
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.12.1
|
4
4
|
Summary: Fast and easy dependency injection framework.
|
5
5
|
Home-page: https://github.com/100nm/python-injection
|
6
6
|
License: MIT
|
7
7
|
Keywords: dependencies,dependency,inject,injection
|
8
8
|
Author: remimd
|
9
|
-
Requires-Python: >=3.12
|
9
|
+
Requires-Python: >=3.12, <4
|
10
10
|
Classifier: Development Status :: 4 - Beta
|
11
|
-
Classifier: Intended Audience :: Developers
|
12
|
-
Classifier: License :: OSI Approved :: MIT License
|
13
|
-
Classifier: Natural Language :: English
|
14
|
-
Classifier: Operating System :: OS Independent
|
15
|
-
Classifier: Programming Language :: Python
|
16
|
-
Classifier: Programming Language :: Python :: 3
|
17
|
-
Classifier: Programming Language :: Python :: 3.12
|
18
|
-
Classifier: Programming Language :: Python :: 3.13
|
19
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
20
11
|
Classifier: Topic :: Software Development :: Libraries
|
21
12
|
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
22
13
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
23
14
|
Classifier: Topic :: Software Development :: Testing
|
15
|
+
Classifier: Programming Language :: Python
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
18
|
+
Classifier: Operating System :: OS Independent
|
19
|
+
Classifier: Intended Audience :: Developers
|
20
|
+
Classifier: Natural Language :: English
|
24
21
|
Classifier: Typing :: Typed
|
25
22
|
Project-URL: Repository, https://github.com/100nm/python-injection
|
26
23
|
Description-Content-Type: text/markdown
|
@@ -0,0 +1,24 @@
|
|
1
|
+
injection/__init__.py,sha256=1MI9kXuQfsqLGQK_5-Zm4JjecqopjGNlhsAW8iihn9M,919
|
2
|
+
injection/__init__.pyi,sha256=Gwtvo6sJVizqz0pTKNaG-Jz_NW0gSqEsoZF7T6p3V1s,8820
|
3
|
+
injection/_core/__init__.py,sha256=XERocCxCZBxPGIaOR37yeiQOZyvjHQ6a4rgRmlkUSuU,1367
|
4
|
+
injection/_core/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
+
injection/_core/common/asynchronous.py,sha256=KIgFaCxohmVvVThkMWqo8XrevZXHyLLZODLi76Jmx08,1544
|
6
|
+
injection/_core/common/event.py,sha256=kev8WUESAXzMn11EJsbTcICaCvYiD556E6BOLvQ54s4,1243
|
7
|
+
injection/_core/common/invertible.py,sha256=YZlAdh6bNJgf1-74TRjwJTm8xrlgY95ZhOUGLSJ4XcY,482
|
8
|
+
injection/_core/common/lazy.py,sha256=ZKx2O9CCFsF9F0SLM4zb7jSLksJUv-FBLCPlWltMN5k,1398
|
9
|
+
injection/_core/common/threading.py,sha256=OXm7L3p8c7O7eSkU-RTR7cobqIGMhuo-7gpDXsWKDNQ,214
|
10
|
+
injection/_core/common/type.py,sha256=c4QfvbkMfYMlNxqt-vq6QJ83ubMnw6AIVI2Rp-tV1PI,1550
|
11
|
+
injection/_core/descriptors.py,sha256=y1rFTQdCDIMLVQfuQE8ZkTPlVZKgzvwZ2Y20Si05DwM,662
|
12
|
+
injection/_core/hook.py,sha256=Qv505pr3kjOE6UitftlLh9JKX9OCNqZBRtHbFha1gqM,3130
|
13
|
+
injection/_core/injectables.py,sha256=rBcrTYRpZ69LkHSGm6bve6TGPwf66XkuK2XVACwcRNc,2427
|
14
|
+
injection/_core/module.py,sha256=xUgveXJS5PXd3DtfLBH7InafEtSShGND4ccYkCIfGqk,28611
|
15
|
+
injection/exceptions.py,sha256=-5Shs7R5rctQXhpMLfcjiMBCzrtFWxC88qETUIHz57s,692
|
16
|
+
injection/integrations/__init__.py,sha256=NYLcstr4ESdLj326LlDub143z6JGM1z1pCOVWhBXK10,304
|
17
|
+
injection/integrations/fastapi.py,sha256=OZyZNxqJvOr-c5Ee0G1-oHhGF7067Ugjl_qDnIiAC1I,1760
|
18
|
+
injection/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
19
|
+
injection/testing/__init__.py,sha256=Wd9sq43CJCV7GjYFSIaikIf4hJ5lfVNS7GP3iI8a1X8,719
|
20
|
+
injection/testing/__init__.pyi,sha256=Dyf1LjSj3LrjghXjM2xkMiINg-OPWQMtjCEnnfWzaDY,372
|
21
|
+
injection/utils.py,sha256=79VoIgxO1MNb_FlfRRbzfx3RXX3DPDtoxMgngfmNF-Q,1920
|
22
|
+
python_injection-0.12.1.dist-info/METADATA,sha256=2TdNJGHf1TIvBrbRkVjfimNJR7frm4HDoKDnAYiop98,2958
|
23
|
+
python_injection-0.12.1.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
|
24
|
+
python_injection-0.12.1.dist-info/RECORD,,
|
@@ -1,34 +0,0 @@
|
|
1
|
-
from typing import Any, override
|
2
|
-
|
3
|
-
from injection import Module, mod
|
4
|
-
from injection.integrations import _is_installed
|
5
|
-
|
6
|
-
__all__ = ("InjectionServices",)
|
7
|
-
|
8
|
-
if _is_installed("blacksheep", __name__):
|
9
|
-
from rodi import ContainerProtocol
|
10
|
-
|
11
|
-
|
12
|
-
class InjectionServices(ContainerProtocol):
|
13
|
-
"""
|
14
|
-
BlackSheep dependency injection container implemented with `python-injection`.
|
15
|
-
"""
|
16
|
-
|
17
|
-
__slots__ = ("__module",)
|
18
|
-
|
19
|
-
__module: Module
|
20
|
-
|
21
|
-
def __init__(self, module: Module | None = None) -> None:
|
22
|
-
self.__module = module or mod()
|
23
|
-
|
24
|
-
@override
|
25
|
-
def __contains__(self, item: Any) -> bool:
|
26
|
-
return item in self.__module
|
27
|
-
|
28
|
-
@override
|
29
|
-
def register(self, obj_type: type | Any, *args: Any, **kwargs: Any) -> None:
|
30
|
-
self.__module.injectable(obj_type)
|
31
|
-
|
32
|
-
@override
|
33
|
-
def resolve[T](self, obj_type: type[T] | Any, *args: Any, **kwargs: Any) -> T:
|
34
|
-
return self.__module.find_instance(obj_type)
|
@@ -1,23 +0,0 @@
|
|
1
|
-
injection/__init__.py,sha256=4JWr0tMlFJb6Tz2Qsd7AupLiMh13XzleBtViJlWgdZA,833
|
2
|
-
injection/__init__.pyi,sha256=Tj6p9OonN4YEXvjswPSFOCSf6Eq3MidhBHR8ewuFc2w,7927
|
3
|
-
injection/_core/__init__.py,sha256=VMGLfdu0gYh82mt7zS297rQ7CE_gHVy0gRdI8RY_ZLY,1361
|
4
|
-
injection/_core/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
-
injection/_core/common/event.py,sha256=kev8WUESAXzMn11EJsbTcICaCvYiD556E6BOLvQ54s4,1243
|
6
|
-
injection/_core/common/invertible.py,sha256=QYXMqLrkAkz_7mq-jEYKtBr1CQ5aqzplP0FG9fS0g2Y,502
|
7
|
-
injection/_core/common/lazy.py,sha256=kCO1q4S6AdBhsP5RrihBJpgfeR4hxvMqSz1cpCgBdjo,1482
|
8
|
-
injection/_core/common/threading.py,sha256=OXm7L3p8c7O7eSkU-RTR7cobqIGMhuo-7gpDXsWKDNQ,214
|
9
|
-
injection/_core/common/type.py,sha256=TQTD-f_rnAHS0VgfkWxNFU8HAWPvkAktNDQ9_23JLHM,1705
|
10
|
-
injection/_core/descriptors.py,sha256=1DxrJpUXK2exSLAmdMHLNRRn7EBhQyu_vVvrchif2sw,696
|
11
|
-
injection/_core/hook.py,sha256=_TcwhF_DONfcoBz58RxVLeA950Rs8wtZSLGepZwGBRk,3009
|
12
|
-
injection/_core/module.py,sha256=zvYqUIAV9saTYGBuKbR4tNk2AFrMxyFxNPmvMMmKoe4,25300
|
13
|
-
injection/exceptions.py,sha256=-5Shs7R5rctQXhpMLfcjiMBCzrtFWxC88qETUIHz57s,692
|
14
|
-
injection/integrations/__init__.py,sha256=NYLcstr4ESdLj326LlDub143z6JGM1z1pCOVWhBXK10,304
|
15
|
-
injection/integrations/blacksheep.py,sha256=yO5gLb_l4W3bNPFt-v2qWIL9R8PNon4JmOxQEHdi-5o,923
|
16
|
-
injection/integrations/fastapi.py,sha256=j5ASbMszua-Ti9A_dgFO629RjSIzIVbck78Ymz6CiTo,1723
|
17
|
-
injection/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
18
|
-
injection/testing/__init__.py,sha256=Wd9sq43CJCV7GjYFSIaikIf4hJ5lfVNS7GP3iI8a1X8,719
|
19
|
-
injection/testing/__init__.pyi,sha256=6ZXbbS-9ppMdkxd03I6yBNurmR3Xw7sM_qiokibkLeY,386
|
20
|
-
injection/utils.py,sha256=79VoIgxO1MNb_FlfRRbzfx3RXX3DPDtoxMgngfmNF-Q,1920
|
21
|
-
python_injection-0.11.0.dist-info/METADATA,sha256=whi_71OOame5OSWStDfKMvHxCXQjmKhgCybFhe2WA7s,3110
|
22
|
-
python_injection-0.11.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
23
|
-
python_injection-0.11.0.dist-info/RECORD,,
|