python-injection 0.19.4__py3-none-any.whl → 0.19.5.post0__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 +64 -34
- injection/_core/common/type.py +5 -5
- injection/_core/module.py +8 -6
- {python_injection-0.19.4.dist-info → python_injection-0.19.5.post0.dist-info}/METADATA +1 -1
- {python_injection-0.19.4.dist-info → python_injection-0.19.5.post0.dist-info}/RECORD +7 -7
- {python_injection-0.19.4.dist-info → python_injection-0.19.5.post0.dist-info}/WHEEL +0 -0
- {python_injection-0.19.4.dist-info → python_injection-0.19.5.post0.dist-info}/licenses/LICENSE +0 -0
injection/__init__.pyi
CHANGED
@@ -136,6 +136,7 @@ class Module:
|
|
136
136
|
|
137
137
|
With `threadsafe=True`, the injection logic is wrapped in a `threading.RLock`.
|
138
138
|
"""
|
139
|
+
|
139
140
|
@overload
|
140
141
|
def inject[T](
|
141
142
|
self,
|
@@ -145,13 +146,13 @@ class Module:
|
|
145
146
|
threadsafe: bool | None = ...,
|
146
147
|
) -> type[T]: ...
|
147
148
|
@overload
|
148
|
-
def inject
|
149
|
+
def inject(
|
149
150
|
self,
|
150
151
|
wrapped: None = ...,
|
151
152
|
/,
|
152
153
|
*,
|
153
154
|
threadsafe: bool | None = ...,
|
154
|
-
) -> _Decorator[Callable[
|
155
|
+
) -> _Decorator[Callable[..., Any] | type]: ...
|
155
156
|
@overload
|
156
157
|
def injectable[**P, T](
|
157
158
|
self,
|
@@ -192,20 +193,27 @@ class Module:
|
|
192
193
|
mode: Mode | ModeStr = ...,
|
193
194
|
) -> type[T]: ...
|
194
195
|
@overload
|
195
|
-
def injectable[
|
196
|
+
def injectable[T](
|
196
197
|
self,
|
197
198
|
wrapped: None = ...,
|
198
199
|
/,
|
199
200
|
*,
|
200
201
|
cls: _InjectableFactory[T] = ...,
|
201
202
|
inject: bool = ...,
|
202
|
-
on: _TypeInfo[T]
|
203
|
+
on: _TypeInfo[T],
|
204
|
+
mode: Mode | ModeStr = ...,
|
205
|
+
) -> _Decorator[Callable[..., T] | Callable[..., Awaitable[T]] | type[T]]: ...
|
206
|
+
@overload
|
207
|
+
def injectable(
|
208
|
+
self,
|
209
|
+
wrapped: None = ...,
|
210
|
+
/,
|
211
|
+
*,
|
212
|
+
cls: _InjectableFactory[Any] = ...,
|
213
|
+
inject: bool = ...,
|
214
|
+
on: tuple[()] = ...,
|
203
215
|
mode: Mode | ModeStr = ...,
|
204
|
-
) ->
|
205
|
-
_Decorator[Callable[P, T]]
|
206
|
-
| _Decorator[Callable[P, Awaitable[T]]]
|
207
|
-
| _Decorator[type[T]]
|
208
|
-
): ...
|
216
|
+
) -> _Decorator[Callable[..., Any] | type]: ...
|
209
217
|
@overload
|
210
218
|
def singleton[**P, T](
|
211
219
|
self,
|
@@ -243,40 +251,57 @@ class Module:
|
|
243
251
|
mode: Mode | ModeStr = ...,
|
244
252
|
) -> type[T]: ...
|
245
253
|
@overload
|
246
|
-
def singleton[
|
254
|
+
def singleton[T](
|
247
255
|
self,
|
248
256
|
wrapped: None = ...,
|
249
257
|
/,
|
250
258
|
*,
|
251
259
|
inject: bool = ...,
|
252
|
-
on: _TypeInfo[T]
|
260
|
+
on: _TypeInfo[T],
|
253
261
|
mode: Mode | ModeStr = ...,
|
254
|
-
) ->
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
262
|
+
) -> _Decorator[Callable[..., T] | Callable[..., Awaitable[T]] | type[T]]: ...
|
263
|
+
@overload
|
264
|
+
def singleton(
|
265
|
+
self,
|
266
|
+
wrapped: None = ...,
|
267
|
+
/,
|
268
|
+
*,
|
269
|
+
inject: bool = ...,
|
270
|
+
on: tuple[()] = ...,
|
271
|
+
mode: Mode | ModeStr = ...,
|
272
|
+
) -> _Decorator[Callable[..., Any] | type]: ...
|
273
|
+
@overload
|
274
|
+
def scoped[T](
|
260
275
|
self,
|
261
276
|
scope_name: str,
|
262
277
|
/,
|
263
278
|
*,
|
264
279
|
inject: bool = ...,
|
265
|
-
on: _TypeInfo[T]
|
280
|
+
on: _TypeInfo[T],
|
266
281
|
mode: Mode | ModeStr = ...,
|
267
|
-
) ->
|
268
|
-
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
282
|
+
) -> _Decorator[
|
283
|
+
Callable[..., T]
|
284
|
+
| Callable[..., Awaitable[T]]
|
285
|
+
| Callable[..., AsyncIterator[T]]
|
286
|
+
| Callable[..., Iterator[T]]
|
287
|
+
| type[T]
|
288
|
+
]:
|
274
289
|
"""
|
275
290
|
Decorator applicable to a class or function or generator function. It is used
|
276
291
|
to indicate how the scoped instance will be constructed. At injection time, the
|
277
292
|
injected instance is retrieved from the scope.
|
278
293
|
"""
|
279
294
|
|
295
|
+
@overload
|
296
|
+
def scoped(
|
297
|
+
self,
|
298
|
+
scope_name: str,
|
299
|
+
/,
|
300
|
+
*,
|
301
|
+
inject: bool = ...,
|
302
|
+
on: tuple[()] = ...,
|
303
|
+
mode: Mode | ModeStr = ...,
|
304
|
+
) -> _Decorator[Callable[..., Any] | type]: ...
|
280
305
|
@overload
|
281
306
|
def should_be_injectable[T](self, wrapped: type[T], /) -> type[T]:
|
282
307
|
"""
|
@@ -286,11 +311,11 @@ class Module:
|
|
286
311
|
"""
|
287
312
|
|
288
313
|
@overload
|
289
|
-
def should_be_injectable
|
314
|
+
def should_be_injectable(
|
290
315
|
self,
|
291
316
|
wrapped: None = ...,
|
292
317
|
/,
|
293
|
-
) -> _Decorator[type
|
318
|
+
) -> _Decorator[type]: ...
|
294
319
|
@overload
|
295
320
|
def constant[**P, T](
|
296
321
|
self,
|
@@ -325,18 +350,23 @@ class Module:
|
|
325
350
|
mode: Mode | ModeStr = ...,
|
326
351
|
) -> type[T]: ...
|
327
352
|
@overload
|
328
|
-
def constant[
|
353
|
+
def constant[T](
|
329
354
|
self,
|
330
355
|
wrapped: None = ...,
|
331
356
|
/,
|
332
357
|
*,
|
333
|
-
on: _TypeInfo[T]
|
358
|
+
on: _TypeInfo[T],
|
359
|
+
mode: Mode | ModeStr = ...,
|
360
|
+
) -> _Decorator[Callable[..., T] | Callable[..., Awaitable[T]] | type[T]]: ...
|
361
|
+
@overload
|
362
|
+
def constant(
|
363
|
+
self,
|
364
|
+
wrapped: None = ...,
|
365
|
+
/,
|
366
|
+
*,
|
367
|
+
on: tuple[()] = ...,
|
334
368
|
mode: Mode | ModeStr = ...,
|
335
|
-
) ->
|
336
|
-
_Decorator[Callable[P, T]]
|
337
|
-
| _Decorator[Callable[P, Awaitable[T]]]
|
338
|
-
| _Decorator[type[T]]
|
339
|
-
): ...
|
369
|
+
) -> _Decorator[Callable[..., Any] | type]: ...
|
340
370
|
def set_constant[T](
|
341
371
|
self,
|
342
372
|
instance: T,
|
injection/_core/common/type.py
CHANGED
@@ -54,10 +54,10 @@ def get_return_hint[T](function: Callable[..., T]) -> InputType[T] | None:
|
|
54
54
|
|
55
55
|
def get_yield_hint[T](
|
56
56
|
function: Callable[..., Iterator[T]] | Callable[..., AsyncIterator[T]],
|
57
|
-
) -> InputType[T] |
|
57
|
+
) -> tuple[InputType[T]] | tuple[()]:
|
58
58
|
return_type = get_return_hint(function)
|
59
59
|
|
60
|
-
if get_origin(return_type)
|
60
|
+
if get_origin(return_type) in {
|
61
61
|
AsyncGenerator,
|
62
62
|
AsyncIterable,
|
63
63
|
AsyncIterator,
|
@@ -65,10 +65,10 @@ def get_yield_hint[T](
|
|
65
65
|
Iterable,
|
66
66
|
Iterator,
|
67
67
|
}:
|
68
|
-
|
68
|
+
for arg in get_args(return_type):
|
69
|
+
return (arg,)
|
69
70
|
|
70
|
-
|
71
|
-
return next(iter(args), None)
|
71
|
+
return ()
|
72
72
|
|
73
73
|
|
74
74
|
def standardize_types(
|
injection/_core/module.py
CHANGED
@@ -337,12 +337,14 @@ class Locator(Broker):
|
|
337
337
|
cls: InputType[T],
|
338
338
|
) -> bool:
|
339
339
|
new_mode, existing_mode = new.mode, existing.mode
|
340
|
-
is_override = new_mode == Mode.OVERRIDE
|
341
340
|
|
342
|
-
if new_mode ==
|
341
|
+
if new_mode == Mode.OVERRIDE:
|
342
|
+
return True
|
343
|
+
|
344
|
+
elif new_mode == existing_mode:
|
343
345
|
raise RuntimeError(f"An injectable already exists for the class `{cls}`.")
|
344
346
|
|
345
|
-
return
|
347
|
+
return new_mode.rank > existing_mode.rank
|
346
348
|
|
347
349
|
@staticmethod
|
348
350
|
def __standardize_inputs[T](
|
@@ -478,16 +480,16 @@ class Module(Broker, EventListener):
|
|
478
480
|
wrapper = contextmanager(wrapped)
|
479
481
|
|
480
482
|
else:
|
483
|
+
hint = (wrapped,) # type: ignore[assignment]
|
481
484
|
injectable_class = SimpleScopedInjectable
|
482
|
-
|
485
|
+
wrapper = wrapped # type: ignore[assignment]
|
483
486
|
|
484
|
-
hints = on if hint is None else (hint, on)
|
485
487
|
self.injectable(
|
486
488
|
wrapper,
|
487
489
|
cls=partial(injectable_class, scope_name=scope_name),
|
488
490
|
ignore_type_hint=True,
|
489
491
|
inject=inject,
|
490
|
-
on=
|
492
|
+
on=(*hint, on),
|
491
493
|
mode=mode,
|
492
494
|
)
|
493
495
|
return wrapped
|
@@ -1,5 +1,5 @@
|
|
1
1
|
injection/__init__.py,sha256=iJm0BbyGZw-Qr5e8d2C3n8-7FiVD-sy4LU_i_n3AgHY,1318
|
2
|
-
injection/__init__.pyi,sha256=
|
2
|
+
injection/__init__.pyi,sha256=8uWRfGfkVCfWBx4X4XsRyo1l7vKym6-vmcMklPyVMqg,15672
|
3
3
|
injection/entrypoint.py,sha256=1JtooUCE9nIvHGAps5ypRb9ZEbgLdLwydkGF-kXMXDY,4953
|
4
4
|
injection/exceptions.py,sha256=v57yMujiq6H_zwwn30A8UYEZX9R9k-bY8FnsdaimPM4,1025
|
5
5
|
injection/loaders.py,sha256=gKlJfe9nXCuB8r6j0RF9_2FHC6YplM8GQYsgRqyxYw8,7257
|
@@ -8,7 +8,7 @@ injection/_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
8
|
injection/_core/asfunction.py,sha256=fTgAAWsDWUz89kYsoSVDXdqYKIuh6HtUW5MohGp3ov4,1767
|
9
9
|
injection/_core/descriptors.py,sha256=1OX6JnM8Ux14vW1JSW3FzPgKc2VMTKqJUYBGT3Ypafg,800
|
10
10
|
injection/_core/injectables.py,sha256=fxhiGv7qTCbUunhhd6a3ahosFmgznUFsEvqlwxi4gS4,6098
|
11
|
-
injection/_core/module.py,sha256=
|
11
|
+
injection/_core/module.py,sha256=Nd7IVFX0Cgw2FDyH0fuOLozXloSaTXcm-pQ-QK6Pf-c,32672
|
12
12
|
injection/_core/scope.py,sha256=r094k1Vjvwm0hTf7AQGYrxxvqQgb7_CDVUKaHQ8wyeM,8772
|
13
13
|
injection/_core/slots.py,sha256=g9TG6CbqRzCsjg01iPyfRtTTUCJnnJOwcj9mJabH0dc,37
|
14
14
|
injection/_core/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -18,13 +18,13 @@ injection/_core/common/invertible.py,sha256=gA_vw5nBjgp_w9MrDK5jMO8lhuOQWON8BbPp
|
|
18
18
|
injection/_core/common/key.py,sha256=ghkZD-Y8Moz6SEPNgMh3xgsZUjDVq-XYAmXaCu5VuCA,80
|
19
19
|
injection/_core/common/lazy.py,sha256=hZvz9LhlYxVkD_D8VBAvQmy7YuVaaw075jq0XM0w9_Y,1193
|
20
20
|
injection/_core/common/threading.py,sha256=kwRXNa9ocndIqeZA9kMHjEa8SBpHFcJARj1bgrWCpxE,225
|
21
|
-
injection/_core/common/type.py,sha256=
|
21
|
+
injection/_core/common/type.py,sha256=U7PtuH-FuMgw75LB7xy-arJRJXojxsJDQbhnTqA4P-o,2567
|
22
22
|
injection/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
23
23
|
injection/ext/fastapi.py,sha256=fiy3-mZIIwGcql3Y5ekFX8_7hALzqXP5u40qbtNE73o,1441
|
24
24
|
injection/ext/fastapi.pyi,sha256=HLs7mfruIEFRrN_Xf8oCvSa4qwHWfwm6HHU_KMedXkE,185
|
25
25
|
injection/testing/__init__.py,sha256=bJ7WXBXrw4rHc91AFVFnOwFLWOlpvX9Oh2SnRQ_NESo,919
|
26
26
|
injection/testing/__init__.pyi,sha256=raGsGlxwbz3jkzJwA_5oCIE1emWINjT2UuwzbnqRb-0,577
|
27
|
-
python_injection-0.19.
|
28
|
-
python_injection-0.19.
|
29
|
-
python_injection-0.19.
|
30
|
-
python_injection-0.19.
|
27
|
+
python_injection-0.19.5.post0.dist-info/METADATA,sha256=vaFb1wrfK4K1AGaoimYkxPtzCgHJX37dngLeIELmMBw,4307
|
28
|
+
python_injection-0.19.5.post0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
29
|
+
python_injection-0.19.5.post0.dist-info/licenses/LICENSE,sha256=oC77BOa9kaaQni5rW-Z-ytz3E5h4EVg248BHg9UFgyg,1063
|
30
|
+
python_injection-0.19.5.post0.dist-info/RECORD,,
|
File without changes
|
{python_injection-0.19.4.dist-info → python_injection-0.19.5.post0.dist-info}/licenses/LICENSE
RENAMED
File without changes
|