python-injection 0.9.3__py3-none-any.whl → 0.9.4__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 python-injection might be problematic. Click here for more details.
- injection/__init__.py +16 -9
- injection/__init__.pyi +15 -10
- injection/common/tools/type.py +3 -4
- injection/core/module.py +3 -3
- injection/integrations/blacksheep.py +3 -3
- injection/testing/__init__.py +9 -14
- injection/testing/__init__.pyi +5 -8
- {python_injection-0.9.3.dist-info → python_injection-0.9.4.dist-info}/METADATA +1 -1
- {python_injection-0.9.3.dist-info → python_injection-0.9.4.dist-info}/RECORD +10 -10
- {python_injection-0.9.3.dist-info → python_injection-0.9.4.dist-info}/WHEEL +0 -0
injection/__init__.py
CHANGED
|
@@ -7,23 +7,30 @@ __all__ = (
|
|
|
7
7
|
"InjectableMode",
|
|
8
8
|
"Module",
|
|
9
9
|
"ModulePriority",
|
|
10
|
+
"find_instance",
|
|
10
11
|
"get_instance",
|
|
11
12
|
"get_lazy_instance",
|
|
12
13
|
"inject",
|
|
13
14
|
"injectable",
|
|
15
|
+
"mod",
|
|
14
16
|
"set_constant",
|
|
15
17
|
"should_be_injectable",
|
|
16
18
|
"singleton",
|
|
17
19
|
)
|
|
18
20
|
|
|
19
|
-
_module = Module.default()
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
injectable = _module.injectable
|
|
25
|
-
set_constant = _module.set_constant
|
|
26
|
-
should_be_injectable = _module.should_be_injectable
|
|
27
|
-
singleton = _module.singleton
|
|
22
|
+
def mod(name: str = None, /) -> Module:
|
|
23
|
+
if name is None:
|
|
24
|
+
return Module.default()
|
|
28
25
|
|
|
29
|
-
|
|
26
|
+
return Module.from_name(name)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
find_instance = mod().find_instance
|
|
30
|
+
get_instance = mod().get_instance
|
|
31
|
+
get_lazy_instance = mod().get_lazy_instance
|
|
32
|
+
inject = mod().inject
|
|
33
|
+
injectable = mod().injectable
|
|
34
|
+
set_constant = mod().set_constant
|
|
35
|
+
should_be_injectable = mod().should_be_injectable
|
|
36
|
+
singleton = mod().singleton
|
injection/__init__.pyi
CHANGED
|
@@ -19,18 +19,23 @@ from .core import InjectableFactory
|
|
|
19
19
|
from .core import ModeStr as InjectableModeStr
|
|
20
20
|
from .core import PriorityStr as ModulePriorityStr
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
_: Module = ...
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
find_instance = _.find_instance
|
|
25
|
+
get_instance = _.get_instance
|
|
26
|
+
get_lazy_instance = _.get_lazy_instance
|
|
27
|
+
inject = _.inject
|
|
28
|
+
injectable = _.injectable
|
|
29
|
+
set_constant = _.set_constant
|
|
30
|
+
should_be_injectable = _.should_be_injectable
|
|
31
|
+
singleton = _.singleton
|
|
31
32
|
|
|
32
|
-
del
|
|
33
|
+
del _
|
|
33
34
|
|
|
35
|
+
def mod(name: str = ..., /) -> Module:
|
|
36
|
+
"""
|
|
37
|
+
Short syntax for `Module.from_name`.
|
|
38
|
+
"""
|
|
34
39
|
@final
|
|
35
40
|
class Module:
|
|
36
41
|
"""
|
|
@@ -103,7 +108,7 @@ class Module:
|
|
|
103
108
|
that no dependencies are resolved, so the module doesn't need to be locked.
|
|
104
109
|
"""
|
|
105
110
|
|
|
106
|
-
def
|
|
111
|
+
def find_instance[T](self, cls: type[T]) -> T:
|
|
107
112
|
"""
|
|
108
113
|
Function used to retrieve an instance associated with the type passed in
|
|
109
114
|
parameter or an exception will be raised.
|
injection/common/tools/type.py
CHANGED
|
@@ -59,10 +59,9 @@ def analyze_types(*types: type | Any) -> Iterator[TypeReport[Any]]:
|
|
|
59
59
|
|
|
60
60
|
def get_return_types(*args: TypeInfo[Any]) -> Iterator[type | UnionType]:
|
|
61
61
|
for arg in args:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
):
|
|
62
|
+
origin = get_origin(arg) or arg
|
|
63
|
+
|
|
64
|
+
if isinstance(origin, Iterable) and not isinstance(origin, type | str):
|
|
66
65
|
inner_args = arg
|
|
67
66
|
|
|
68
67
|
elif isfunction(arg):
|
injection/core/module.py
CHANGED
|
@@ -488,13 +488,13 @@ class Module(EventListener, Broker):
|
|
|
488
488
|
|
|
489
489
|
return decorator(wrapped) if wrapped else decorator
|
|
490
490
|
|
|
491
|
-
def
|
|
491
|
+
def find_instance[T](self, cls: type[T]) -> T:
|
|
492
492
|
injectable = self[cls]
|
|
493
493
|
return injectable.get_instance()
|
|
494
494
|
|
|
495
495
|
def get_instance[T](self, cls: type[T]) -> T | None:
|
|
496
496
|
try:
|
|
497
|
-
return self.
|
|
497
|
+
return self.find_instance(cls)
|
|
498
498
|
except KeyError:
|
|
499
499
|
return None
|
|
500
500
|
|
|
@@ -627,7 +627,7 @@ class Module(EventListener, Broker):
|
|
|
627
627
|
) from exc
|
|
628
628
|
|
|
629
629
|
def __send_debug(self, message: object):
|
|
630
|
-
for logger in self.__loggers:
|
|
630
|
+
for logger in tuple(self.__loggers):
|
|
631
631
|
logger.debug(message)
|
|
632
632
|
|
|
633
633
|
@classmethod
|
|
@@ -2,7 +2,7 @@ from typing import Any
|
|
|
2
2
|
|
|
3
3
|
from rodi import ContainerProtocol
|
|
4
4
|
|
|
5
|
-
from injection import Module
|
|
5
|
+
from injection import Module, mod
|
|
6
6
|
|
|
7
7
|
__all__ = ("InjectionServices",)
|
|
8
8
|
|
|
@@ -15,7 +15,7 @@ class InjectionServices(ContainerProtocol):
|
|
|
15
15
|
__slots__ = ("__module",)
|
|
16
16
|
|
|
17
17
|
def __init__(self, module: Module = None):
|
|
18
|
-
self.__module = module or
|
|
18
|
+
self.__module = module or mod()
|
|
19
19
|
|
|
20
20
|
def __contains__(self, item: Any) -> bool:
|
|
21
21
|
return item in self.__module
|
|
@@ -25,4 +25,4 @@ class InjectionServices(ContainerProtocol):
|
|
|
25
25
|
return self
|
|
26
26
|
|
|
27
27
|
def resolve[T](self, obj_type: type[T] | Any, *args, **kwargs) -> T:
|
|
28
|
-
return self.__module.
|
|
28
|
+
return self.__module.find_instance(obj_type)
|
injection/testing/__init__.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from contextlib import contextmanager
|
|
2
|
+
from functools import partial
|
|
2
3
|
|
|
3
|
-
from injection import Module, ModulePriority
|
|
4
|
+
from injection import Module, ModulePriority, mod
|
|
4
5
|
|
|
5
6
|
__all__ = (
|
|
6
7
|
"set_test_constant",
|
|
@@ -11,24 +12,18 @@ __all__ = (
|
|
|
11
12
|
)
|
|
12
13
|
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
return Module.from_name("testing")
|
|
15
|
+
testing_mod = partial(mod, "testing")
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
should_be_test_injectable = _module.should_be_injectable
|
|
22
|
-
test_injectable = _module.injectable
|
|
23
|
-
test_singleton = _module.singleton
|
|
24
|
-
|
|
25
|
-
del _module
|
|
17
|
+
set_test_constant = testing_mod().set_constant
|
|
18
|
+
should_be_test_injectable = testing_mod().should_be_injectable
|
|
19
|
+
test_injectable = testing_mod().injectable
|
|
20
|
+
test_singleton = testing_mod().singleton
|
|
26
21
|
|
|
27
22
|
|
|
28
23
|
@contextmanager
|
|
29
24
|
def use_test_injectables(*, on: Module = None, test_module: Module = None):
|
|
30
|
-
on = on or
|
|
31
|
-
test_module = test_module or
|
|
25
|
+
on = on or mod()
|
|
26
|
+
test_module = test_module or testing_mod()
|
|
32
27
|
|
|
33
28
|
for module in (on, test_module):
|
|
34
29
|
module.unlock()
|
injection/testing/__init__.pyi
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
from contextlib import ContextDecorator
|
|
2
2
|
from typing import ContextManager
|
|
3
3
|
|
|
4
|
+
import injection as _
|
|
4
5
|
from injection import Module
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
test_injectable = _module.injectable
|
|
11
|
-
test_singleton = _module.singleton
|
|
12
|
-
|
|
13
|
-
del _module
|
|
7
|
+
set_test_constant = _.set_constant
|
|
8
|
+
should_be_test_injectable = _.should_be_injectable
|
|
9
|
+
test_injectable = _.injectable
|
|
10
|
+
test_singleton = _.singleton
|
|
14
11
|
|
|
15
12
|
def use_test_injectables(
|
|
16
13
|
*,
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
injection/__init__.py,sha256=
|
|
2
|
-
injection/__init__.pyi,sha256=
|
|
1
|
+
injection/__init__.py,sha256=4kwoQN5V-fcasIbZ3G3_zCbmnvGCqTilJ92Lwu62wXc,798
|
|
2
|
+
injection/__init__.pyi,sha256=BQ8Fd7EDGBO8YMq95JxNWZACIo75EKW28-dr6zK8S90,6396
|
|
3
3
|
injection/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
injection/common/event.py,sha256=5Rdb2m3vAMCic8cQAVkStJDbrDrW_lk6kav8wYwmexM,1283
|
|
5
5
|
injection/common/invertible.py,sha256=a-fht4TxMnki-oFFaZrDz52X_LWx0NU60KQlw72pzs4,528
|
|
6
6
|
injection/common/lazy.py,sha256=SpQhlGBpMpeD9R5R-CdIInSVDv1XZWvnkERp1J6wsus,1315
|
|
7
7
|
injection/common/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
8
|
injection/common/tools/threading.py,sha256=HlvP6k_-eZaK8JbB2b9PP171IZVe_0W2oMYsw3ebdKA,187
|
|
9
|
-
injection/common/tools/type.py,sha256=
|
|
9
|
+
injection/common/tools/type.py,sha256=DP8_XG0iaqr6CwKqgBVHQfAO5FcgJjyzcFGAAhuyNZk,1732
|
|
10
10
|
injection/core/__init__.py,sha256=zuf0ubI2dHnbjn1059eduhS-ACIkkROa6-dhp10krh0,22
|
|
11
|
-
injection/core/module.py,sha256=
|
|
11
|
+
injection/core/module.py,sha256=M7fKNnqMhMcZavWnIfcV0Nx9Fl-R375scCcO4IS3QtI,22133
|
|
12
12
|
injection/exceptions.py,sha256=RsWWiWwKSMU0vxXQqQSn6CKHLMrGu4SSzYUAy9OJRXk,626
|
|
13
13
|
injection/integrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
-
injection/integrations/blacksheep.py,sha256=
|
|
14
|
+
injection/integrations/blacksheep.py,sha256=XtDIrU5fQGEyBlxwXG2o7X04k2tCmq2OcCC-h2IYZbE,731
|
|
15
15
|
injection/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
-
injection/testing/__init__.py,sha256=
|
|
17
|
-
injection/testing/__init__.pyi,sha256=
|
|
16
|
+
injection/testing/__init__.py,sha256=buILjhmjPEo8Ma2i1py6ZXtJVziAK2FUa4kQqKftzOo,847
|
|
17
|
+
injection/testing/__init__.pyi,sha256=ier9Sgi2_OTv7ecHusl0worKCKQ5ri3LjJks1qjLeNQ,480
|
|
18
18
|
injection/utils.py,sha256=a_H6RC6cNWbG1NQ-zvtrlgwnfS5Jfu0X6VJwIUIHlSU,974
|
|
19
|
-
python_injection-0.9.
|
|
20
|
-
python_injection-0.9.
|
|
21
|
-
python_injection-0.9.
|
|
19
|
+
python_injection-0.9.4.dist-info/METADATA,sha256=8FdPq1Yi8lB_P9t2QFloHqyGYdgAnbVUelgNOACPqPs,3572
|
|
20
|
+
python_injection-0.9.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
21
|
+
python_injection-0.9.4.dist-info/RECORD,,
|
|
File without changes
|