python-injection 0.18.11__py3-none-any.whl → 0.18.13__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__.pyi +7 -5
- injection/_core/descriptors.py +4 -1
- injection/ext/fastapi.py +1 -1
- injection/loaders.py +15 -0
- {python_injection-0.18.11.dist-info → python_injection-0.18.13.dist-info}/METADATA +1 -1
- {python_injection-0.18.11.dist-info → python_injection-0.18.13.dist-info}/RECORD +8 -8
- {python_injection-0.18.11.dist-info → python_injection-0.18.13.dist-info}/WHEEL +0 -0
- {python_injection-0.18.11.dist-info → python_injection-0.18.13.dist-info}/licenses/LICENSE +0 -0
injection/__init__.pyi
CHANGED
@@ -78,7 +78,9 @@ class LazyInstance[T]:
|
|
78
78
|
cls: _InputType[T],
|
79
79
|
/,
|
80
80
|
default: T = ...,
|
81
|
+
*,
|
81
82
|
module: Module = ...,
|
83
|
+
threadsafe: bool = ...,
|
82
84
|
) -> None: ...
|
83
85
|
@overload
|
84
86
|
def __get__(self, instance: object, owner: type | None = ...) -> T: ...
|
@@ -178,9 +180,9 @@ class Module:
|
|
178
180
|
mode: Mode | ModeStr = ...,
|
179
181
|
) -> Any:
|
180
182
|
"""
|
181
|
-
Decorator applicable to a class
|
182
|
-
|
183
|
-
|
183
|
+
Decorator applicable to a class. It is used to indicate how the constant is
|
184
|
+
constructed. At injection time, the injected instance will always be the same.
|
185
|
+
Unlike `@singleton`, dependencies will not be resolved.
|
184
186
|
"""
|
185
187
|
|
186
188
|
def set_constant[T](
|
@@ -292,8 +294,8 @@ class Module:
|
|
292
294
|
) -> _Invertible[T | Default]:
|
293
295
|
"""
|
294
296
|
Function used to retrieve an instance associated with the type passed in
|
295
|
-
parameter or `NotImplemented`. Return
|
296
|
-
contained in an invertible object, simply use a wavy line (~).
|
297
|
+
parameter or `NotImplemented`. Return an `Invertible` object. To access the
|
298
|
+
instance contained in an invertible object, simply use a wavy line (~).
|
297
299
|
|
298
300
|
Example: instance = ~lazy_instance
|
299
301
|
"""
|
injection/_core/descriptors.py
CHANGED
@@ -15,9 +15,12 @@ class LazyInstance[T]:
|
|
15
15
|
cls: InputType[T],
|
16
16
|
/,
|
17
17
|
default: T = NotImplemented,
|
18
|
+
*,
|
18
19
|
module: Module | None = None,
|
20
|
+
threadsafe: bool = False,
|
19
21
|
) -> None:
|
20
|
-
|
22
|
+
module = module or mod()
|
23
|
+
self.__value = module.get_lazy_instance(cls, default, threadsafe=threadsafe)
|
21
24
|
|
22
25
|
def __get__(
|
23
26
|
self,
|
injection/ext/fastapi.py
CHANGED
@@ -12,7 +12,7 @@ __all__ = ("Inject", "InjectThreadSafe")
|
|
12
12
|
@dataclass(eq=False, frozen=True, slots=True)
|
13
13
|
class FastAPIInject:
|
14
14
|
module: Module = field(default_factory=mod)
|
15
|
-
threadsafe: bool = field(default=False)
|
15
|
+
threadsafe: bool = field(default=False, kw_only=True)
|
16
16
|
|
17
17
|
def __call__[T](
|
18
18
|
self,
|
injection/loaders.py
CHANGED
@@ -149,6 +149,15 @@ class ProfileLoader:
|
|
149
149
|
def __is_empty(self) -> bool:
|
150
150
|
return not self.module_subsets
|
151
151
|
|
152
|
+
def required_module_names(self, name: str | None = None, /) -> frozenset[str]:
|
153
|
+
names = {self.module.name}
|
154
|
+
|
155
|
+
if name is not None:
|
156
|
+
names.add(name)
|
157
|
+
|
158
|
+
subsets = (self.__walk_subsets_for(name) for name in names)
|
159
|
+
return frozenset(itertools.chain.from_iterable(subsets))
|
160
|
+
|
152
161
|
def init(self) -> Self:
|
153
162
|
self.__init_subsets_for(self.module)
|
154
163
|
return self
|
@@ -179,6 +188,12 @@ class ProfileLoader:
|
|
179
188
|
def __mark_initialized(self, module: Module) -> None:
|
180
189
|
self.__initialized_modules.add(module.name)
|
181
190
|
|
191
|
+
def __walk_subsets_for(self, module_name: str) -> Iterator[str]:
|
192
|
+
yield module_name
|
193
|
+
|
194
|
+
for name in self.module_subsets.get(module_name, ()):
|
195
|
+
yield from self.__walk_subsets_for(name)
|
196
|
+
|
182
197
|
|
183
198
|
@runtime_checkable
|
184
199
|
class LoadedProfile(Protocol):
|
@@ -1,11 +1,11 @@
|
|
1
1
|
injection/__init__.py,sha256=7ZRUlO5EEPWO7IlbYHD-8DOX-cg4Np4nYq5fpw-U56o,1259
|
2
|
-
injection/__init__.pyi,sha256=
|
2
|
+
injection/__init__.pyi,sha256=65zhAK9LhuUXhftk7YDq2JJZ2zlPtNQ6UfrXaKcQgcA,10940
|
3
3
|
injection/entrypoint.py,sha256=12b0_zHAFxHCerAoJTIHkhqi3mLkgheECYAaCUZv_DU,4751
|
4
4
|
injection/exceptions.py,sha256=v57yMujiq6H_zwwn30A8UYEZX9R9k-bY8FnsdaimPM4,1025
|
5
|
-
injection/loaders.py,sha256=
|
5
|
+
injection/loaders.py,sha256=EWnbcFdiHJBIALm1foHpPi5clZiAHpVstgKXV0dofiw,7091
|
6
6
|
injection/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
7
|
injection/_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
|
-
injection/_core/descriptors.py,sha256=
|
8
|
+
injection/_core/descriptors.py,sha256=RRng9lx-ET6An1d_244rAv4iLUTQUGvDh1ugLfImuW8,794
|
9
9
|
injection/_core/injectables.py,sha256=Rg1nxDkbcpeX4ELohrNVMguPhN36SNQuD0JKfyfL6bI,6192
|
10
10
|
injection/_core/module.py,sha256=aSUHKLFJ63yx6FgJ6AKpDccaZ-H1YpKQyoaKxb4YXfk,32414
|
11
11
|
injection/_core/scope.py,sha256=NY6YWcIIXqBKTjXVsqsahxbw-bPJiL0CwHp6CyjBGJo,8753
|
@@ -19,11 +19,11 @@ injection/_core/common/lazy.py,sha256=L7C2dB5UBI--W5Kkvntp_jypYhudY3SHqs8rM6jxxs
|
|
19
19
|
injection/_core/common/threading.py,sha256=EsIvJl1brMsi551zzMILsMCXNHYUkQP22Mg4FZhp0hw,211
|
20
20
|
injection/_core/common/type.py,sha256=SCDtmBv9qFvEf5o5tTgCuwMDfuo1fgjSW0bUqA8ACis,2251
|
21
21
|
injection/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
22
|
-
injection/ext/fastapi.py,sha256=
|
22
|
+
injection/ext/fastapi.py,sha256=YdCVO1WgZRhv0CFrDnIdsbeRprtcHb-snIL4B4mpLnk,1388
|
23
23
|
injection/ext/fastapi.pyi,sha256=HLs7mfruIEFRrN_Xf8oCvSa4qwHWfwm6HHU_KMedXkE,185
|
24
24
|
injection/testing/__init__.py,sha256=bJ7WXBXrw4rHc91AFVFnOwFLWOlpvX9Oh2SnRQ_NESo,919
|
25
25
|
injection/testing/__init__.pyi,sha256=raGsGlxwbz3jkzJwA_5oCIE1emWINjT2UuwzbnqRb-0,577
|
26
|
-
python_injection-0.18.
|
27
|
-
python_injection-0.18.
|
28
|
-
python_injection-0.18.
|
29
|
-
python_injection-0.18.
|
26
|
+
python_injection-0.18.13.dist-info/METADATA,sha256=O90MunVYtSYyTrFbbDrdhDFKfbp5i9rPsUdnal4jxGs,3398
|
27
|
+
python_injection-0.18.13.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
28
|
+
python_injection-0.18.13.dist-info/licenses/LICENSE,sha256=oC77BOa9kaaQni5rW-Z-ytz3E5h4EVg248BHg9UFgyg,1063
|
29
|
+
python_injection-0.18.13.dist-info/RECORD,,
|
File without changes
|
File without changes
|