python-injection 0.25.2__tar.gz → 0.25.4__tar.gz
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.
- {python_injection-0.25.2 → python_injection-0.25.4}/PKG-INFO +1 -1
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/__init__.pyi +29 -144
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/_core/asfunction.py +7 -2
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/_core/injectables.py +0 -7
- {python_injection-0.25.2 → python_injection-0.25.4}/pyproject.toml +6 -2
- {python_injection-0.25.2 → python_injection-0.25.4}/.gitignore +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/LICENSE +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/README.md +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/__init__.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/_core/__init__.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/_core/common/__init__.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/_core/common/asynchronous.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/_core/common/event.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/_core/common/invertible.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/_core/common/key.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/_core/common/lazy.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/_core/common/threading.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/_core/common/type.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/_core/descriptors.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/_core/locator.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/_core/module.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/_core/scope.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/_core/slots.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/entrypoint.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/exceptions.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/ext/__init__.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/ext/fastapi.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/ext/fastapi.pyi +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/loaders.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/py.typed +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/testing/__init__.py +0 -0
- {python_injection-0.25.2 → python_injection-0.25.4}/injection/testing/__init__.pyi +0 -0
|
@@ -151,13 +151,13 @@ class Module:
|
|
|
151
151
|
@property
|
|
152
152
|
def is_locked(self) -> bool: ...
|
|
153
153
|
@overload
|
|
154
|
-
def inject[
|
|
154
|
+
def inject[T](
|
|
155
155
|
self,
|
|
156
|
-
wrapped:
|
|
156
|
+
wrapped: T,
|
|
157
157
|
/,
|
|
158
158
|
*,
|
|
159
159
|
threadsafe: bool | None = ...,
|
|
160
|
-
) ->
|
|
160
|
+
) -> T:
|
|
161
161
|
"""
|
|
162
162
|
Decorator applicable to a class or function. Inject function dependencies using
|
|
163
163
|
parameter type annotations. If applied to a class, the dependencies resolved
|
|
@@ -166,14 +166,6 @@ class Module:
|
|
|
166
166
|
With `threadsafe=True`, the injection logic is wrapped in a `threading.RLock`.
|
|
167
167
|
"""
|
|
168
168
|
|
|
169
|
-
@overload
|
|
170
|
-
def inject[T](
|
|
171
|
-
self,
|
|
172
|
-
wrapped: type[T],
|
|
173
|
-
/,
|
|
174
|
-
*,
|
|
175
|
-
threadsafe: bool | None = ...,
|
|
176
|
-
) -> type[T]: ...
|
|
177
169
|
@overload
|
|
178
170
|
def inject(
|
|
179
171
|
self,
|
|
@@ -181,57 +173,24 @@ class Module:
|
|
|
181
173
|
/,
|
|
182
174
|
*,
|
|
183
175
|
threadsafe: bool | None = ...,
|
|
184
|
-
) -> _Decorator
|
|
176
|
+
) -> _Decorator: ... # type: ignore[type-arg]
|
|
185
177
|
@overload
|
|
186
|
-
def injectable[
|
|
178
|
+
def injectable[T](
|
|
187
179
|
self,
|
|
188
|
-
wrapped:
|
|
180
|
+
wrapped: T,
|
|
189
181
|
/,
|
|
190
182
|
*,
|
|
191
|
-
cls: _InjectableFactory[
|
|
183
|
+
cls: _InjectableFactory[Any] = ...,
|
|
192
184
|
inject: bool = ...,
|
|
193
|
-
on: _TypeInfo[
|
|
185
|
+
on: _TypeInfo[Any] = ...,
|
|
194
186
|
mode: Mode | ModeStr = ...,
|
|
195
|
-
) ->
|
|
187
|
+
) -> T:
|
|
196
188
|
"""
|
|
197
189
|
Decorator applicable to a class or function. It is used to indicate how the
|
|
198
190
|
injectable will be constructed. At injection time, a new instance will be
|
|
199
191
|
injected each time.
|
|
200
192
|
"""
|
|
201
193
|
|
|
202
|
-
@overload
|
|
203
|
-
def injectable[**P, T]( # type: ignore[overload-overlap]
|
|
204
|
-
self,
|
|
205
|
-
wrapped: Callable[P, Awaitable[T]],
|
|
206
|
-
/,
|
|
207
|
-
*,
|
|
208
|
-
cls: _InjectableFactory[T] = ...,
|
|
209
|
-
inject: bool = ...,
|
|
210
|
-
on: _TypeInfo[T] = ...,
|
|
211
|
-
mode: Mode | ModeStr = ...,
|
|
212
|
-
) -> Callable[P, Awaitable[T]]: ...
|
|
213
|
-
@overload
|
|
214
|
-
def injectable[T](
|
|
215
|
-
self,
|
|
216
|
-
wrapped: type[T],
|
|
217
|
-
/,
|
|
218
|
-
*,
|
|
219
|
-
cls: _InjectableFactory[T] = ...,
|
|
220
|
-
inject: bool = ...,
|
|
221
|
-
on: _TypeInfo[T] = ...,
|
|
222
|
-
mode: Mode | ModeStr = ...,
|
|
223
|
-
) -> type[T]: ...
|
|
224
|
-
@overload
|
|
225
|
-
def injectable[T](
|
|
226
|
-
self,
|
|
227
|
-
wrapped: None = ...,
|
|
228
|
-
/,
|
|
229
|
-
*,
|
|
230
|
-
cls: _InjectableFactory[T] = ...,
|
|
231
|
-
inject: bool = ...,
|
|
232
|
-
on: _TypeInfo[T],
|
|
233
|
-
mode: Mode | ModeStr = ...,
|
|
234
|
-
) -> _Decorator[Callable[..., T] | Callable[..., Awaitable[T]] | type[T]]: ...
|
|
235
194
|
@overload
|
|
236
195
|
def injectable(
|
|
237
196
|
self,
|
|
@@ -240,55 +199,25 @@ class Module:
|
|
|
240
199
|
*,
|
|
241
200
|
cls: _InjectableFactory[Any] = ...,
|
|
242
201
|
inject: bool = ...,
|
|
243
|
-
on:
|
|
202
|
+
on: _TypeInfo[Any] = ...,
|
|
244
203
|
mode: Mode | ModeStr = ...,
|
|
245
|
-
) -> _Decorator
|
|
204
|
+
) -> _Decorator: ... # type: ignore[type-arg]
|
|
246
205
|
@overload
|
|
247
|
-
def singleton[
|
|
206
|
+
def singleton[T](
|
|
248
207
|
self,
|
|
249
|
-
wrapped:
|
|
208
|
+
wrapped: T,
|
|
250
209
|
/,
|
|
251
210
|
*,
|
|
252
211
|
inject: bool = ...,
|
|
253
|
-
on: _TypeInfo[
|
|
212
|
+
on: _TypeInfo[Any] = ...,
|
|
254
213
|
mode: Mode | ModeStr = ...,
|
|
255
|
-
) ->
|
|
214
|
+
) -> T:
|
|
256
215
|
"""
|
|
257
216
|
Decorator applicable to a class or function. It is used to indicate how the
|
|
258
217
|
singleton will be constructed. At injection time, the injected instance will
|
|
259
218
|
always be the same.
|
|
260
219
|
"""
|
|
261
220
|
|
|
262
|
-
@overload
|
|
263
|
-
def singleton[**P, T]( # type: ignore[overload-overlap]
|
|
264
|
-
self,
|
|
265
|
-
wrapped: Callable[P, Awaitable[T]],
|
|
266
|
-
/,
|
|
267
|
-
*,
|
|
268
|
-
inject: bool = ...,
|
|
269
|
-
on: _TypeInfo[T] = ...,
|
|
270
|
-
mode: Mode | ModeStr = ...,
|
|
271
|
-
) -> Callable[P, Awaitable[T]]: ...
|
|
272
|
-
@overload
|
|
273
|
-
def singleton[T](
|
|
274
|
-
self,
|
|
275
|
-
wrapped: type[T],
|
|
276
|
-
/,
|
|
277
|
-
*,
|
|
278
|
-
inject: bool = ...,
|
|
279
|
-
on: _TypeInfo[T] = ...,
|
|
280
|
-
mode: Mode | ModeStr = ...,
|
|
281
|
-
) -> type[T]: ...
|
|
282
|
-
@overload
|
|
283
|
-
def singleton[T](
|
|
284
|
-
self,
|
|
285
|
-
wrapped: None = ...,
|
|
286
|
-
/,
|
|
287
|
-
*,
|
|
288
|
-
inject: bool = ...,
|
|
289
|
-
on: _TypeInfo[T],
|
|
290
|
-
mode: Mode | ModeStr = ...,
|
|
291
|
-
) -> _Decorator[Callable[..., T] | Callable[..., Awaitable[T]] | type[T]]: ...
|
|
292
221
|
@overload
|
|
293
222
|
def singleton(
|
|
294
223
|
self,
|
|
@@ -296,25 +225,18 @@ class Module:
|
|
|
296
225
|
/,
|
|
297
226
|
*,
|
|
298
227
|
inject: bool = ...,
|
|
299
|
-
on:
|
|
228
|
+
on: _TypeInfo[Any] = ...,
|
|
300
229
|
mode: Mode | ModeStr = ...,
|
|
301
|
-
) -> _Decorator
|
|
302
|
-
|
|
303
|
-
def scoped[T](
|
|
230
|
+
) -> _Decorator: ... # type: ignore[type-arg]
|
|
231
|
+
def scoped(
|
|
304
232
|
self,
|
|
305
233
|
scope_name: str,
|
|
306
234
|
/,
|
|
307
235
|
*,
|
|
308
236
|
inject: bool = ...,
|
|
309
|
-
on: _TypeInfo[
|
|
237
|
+
on: _TypeInfo[Any] = ...,
|
|
310
238
|
mode: Mode | ModeStr = ...,
|
|
311
|
-
) -> _Decorator[
|
|
312
|
-
Callable[..., T]
|
|
313
|
-
| Callable[..., Awaitable[T]]
|
|
314
|
-
| Callable[..., AsyncIterator[T]]
|
|
315
|
-
| Callable[..., Iterator[T]]
|
|
316
|
-
| type[T]
|
|
317
|
-
]:
|
|
239
|
+
) -> _Decorator: # type: ignore[type-arg]
|
|
318
240
|
"""
|
|
319
241
|
Decorator applicable to a class or function or generator function. It is used
|
|
320
242
|
to indicate how the scoped instance will be constructed. At injection time, the
|
|
@@ -322,17 +244,7 @@ class Module:
|
|
|
322
244
|
"""
|
|
323
245
|
|
|
324
246
|
@overload
|
|
325
|
-
def
|
|
326
|
-
self,
|
|
327
|
-
scope_name: str,
|
|
328
|
-
/,
|
|
329
|
-
*,
|
|
330
|
-
inject: bool = ...,
|
|
331
|
-
on: tuple[()] = ...,
|
|
332
|
-
mode: Mode | ModeStr = ...,
|
|
333
|
-
) -> _Decorator[Callable[..., Any] | type]: ...
|
|
334
|
-
@overload
|
|
335
|
-
def should_be_injectable[T](self, wrapped: type[T], /) -> type[T]:
|
|
247
|
+
def should_be_injectable[T](self, wrapped: T, /) -> T:
|
|
336
248
|
"""
|
|
337
249
|
Decorator applicable to a class. It is used to specify whether an injectable
|
|
338
250
|
should be registered. Raise an exception at injection time if the class isn't
|
|
@@ -344,62 +256,35 @@ class Module:
|
|
|
344
256
|
self,
|
|
345
257
|
wrapped: None = ...,
|
|
346
258
|
/,
|
|
347
|
-
) -> _Decorator[type]
|
|
259
|
+
) -> _Decorator: ... # type: ignore[type-arg]
|
|
348
260
|
@overload
|
|
349
|
-
def constant[
|
|
261
|
+
def constant[T](
|
|
350
262
|
self,
|
|
351
|
-
wrapped:
|
|
263
|
+
wrapped: T,
|
|
352
264
|
/,
|
|
353
265
|
*,
|
|
354
|
-
on: _TypeInfo[
|
|
266
|
+
on: _TypeInfo[Any] = ...,
|
|
355
267
|
mode: Mode | ModeStr = ...,
|
|
356
|
-
) ->
|
|
268
|
+
) -> T:
|
|
357
269
|
"""
|
|
358
270
|
Decorator applicable to a class or function. It is used to indicate how the
|
|
359
271
|
constant is constructed. At injection time, the injected instance will always
|
|
360
272
|
be the same. Unlike `@singleton`, dependencies will not be resolved.
|
|
361
273
|
"""
|
|
362
274
|
|
|
363
|
-
@overload
|
|
364
|
-
def constant[**P, T]( # type: ignore[overload-overlap]
|
|
365
|
-
self,
|
|
366
|
-
wrapped: Callable[P, Awaitable[T]],
|
|
367
|
-
/,
|
|
368
|
-
*,
|
|
369
|
-
on: _TypeInfo[T] = ...,
|
|
370
|
-
mode: Mode | ModeStr = ...,
|
|
371
|
-
) -> Callable[P, Awaitable[T]]: ...
|
|
372
|
-
@overload
|
|
373
|
-
def constant[T](
|
|
374
|
-
self,
|
|
375
|
-
wrapped: type[T],
|
|
376
|
-
/,
|
|
377
|
-
*,
|
|
378
|
-
on: _TypeInfo[T] = ...,
|
|
379
|
-
mode: Mode | ModeStr = ...,
|
|
380
|
-
) -> type[T]: ...
|
|
381
|
-
@overload
|
|
382
|
-
def constant[T](
|
|
383
|
-
self,
|
|
384
|
-
wrapped: None = ...,
|
|
385
|
-
/,
|
|
386
|
-
*,
|
|
387
|
-
on: _TypeInfo[T],
|
|
388
|
-
mode: Mode | ModeStr = ...,
|
|
389
|
-
) -> _Decorator[Callable[..., T] | Callable[..., Awaitable[T]] | type[T]]: ...
|
|
390
275
|
@overload
|
|
391
276
|
def constant(
|
|
392
277
|
self,
|
|
393
278
|
wrapped: None = ...,
|
|
394
279
|
/,
|
|
395
280
|
*,
|
|
396
|
-
on:
|
|
281
|
+
on: _TypeInfo[Any] = ...,
|
|
397
282
|
mode: Mode | ModeStr = ...,
|
|
398
|
-
) -> _Decorator
|
|
283
|
+
) -> _Decorator: ... # type: ignore[type-arg]
|
|
399
284
|
def set_constant[T](
|
|
400
285
|
self,
|
|
401
286
|
instance: T,
|
|
402
|
-
on: _TypeInfo[
|
|
287
|
+
on: _TypeInfo[Any] = ...,
|
|
403
288
|
*,
|
|
404
289
|
alias: bool = ...,
|
|
405
290
|
mode: Mode | ModeStr = ...,
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
from collections.abc import Callable
|
|
2
2
|
from functools import wraps
|
|
3
3
|
from inspect import iscoroutinefunction
|
|
4
|
-
from typing import Any
|
|
4
|
+
from typing import Any, Protocol
|
|
5
5
|
|
|
6
6
|
from injection._core.common.asynchronous import Caller
|
|
7
7
|
from injection._core.module import Module, mod
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
class _AsFunctionCallable[**P, T](Protocol):
|
|
11
|
+
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T: ...
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
type AsFunctionWrappedType[**P, T] = type[_AsFunctionCallable[P, T]]
|
|
10
15
|
|
|
11
16
|
|
|
12
17
|
def asfunction[**P, T](
|
|
@@ -209,10 +209,6 @@ class ScopedSlotInjectable[T](Injectable[T]):
|
|
|
209
209
|
scope_name: str
|
|
210
210
|
key: SlotKey[T] = field(default_factory=SlotKey)
|
|
211
211
|
|
|
212
|
-
@property
|
|
213
|
-
def is_locked(self) -> bool:
|
|
214
|
-
return in_scope_cache(self.key, self.scope_name)
|
|
215
|
-
|
|
216
212
|
async def aget_instance(self) -> T:
|
|
217
213
|
return self.get_instance()
|
|
218
214
|
|
|
@@ -227,9 +223,6 @@ class ScopedSlotInjectable[T](Injectable[T]):
|
|
|
227
223
|
f"The slot for `{self.cls}` isn't set in the current `{scope_name}` scope."
|
|
228
224
|
) from exc
|
|
229
225
|
|
|
230
|
-
def unlock(self) -> None:
|
|
231
|
-
remove_scoped_values(self.key, self.scope_name)
|
|
232
|
-
|
|
233
226
|
|
|
234
227
|
@dataclass(repr=False, eq=False, frozen=True, slots=True)
|
|
235
228
|
class ShouldBeInjectable[T](Injectable[T]):
|
|
@@ -11,6 +11,7 @@ bench = [
|
|
|
11
11
|
dev = [
|
|
12
12
|
"hatch",
|
|
13
13
|
"mypy",
|
|
14
|
+
"pyright",
|
|
14
15
|
"ruff",
|
|
15
16
|
]
|
|
16
17
|
doc = [
|
|
@@ -30,7 +31,7 @@ test = [
|
|
|
30
31
|
|
|
31
32
|
[project]
|
|
32
33
|
name = "python-injection"
|
|
33
|
-
version = "0.25.
|
|
34
|
+
version = "0.25.4"
|
|
34
35
|
description = "Fast and easy dependency injection framework."
|
|
35
36
|
license = "MIT"
|
|
36
37
|
license-files = ["LICENSE"]
|
|
@@ -76,7 +77,7 @@ exclude_lines = [
|
|
|
76
77
|
]
|
|
77
78
|
|
|
78
79
|
[tool.coverage.run]
|
|
79
|
-
omit = ["bench.py"]
|
|
80
|
+
omit = ["bench.py", "typing_checks/*"]
|
|
80
81
|
|
|
81
82
|
[tool.hatch.build]
|
|
82
83
|
skip-excluded-dirs = true
|
|
@@ -108,6 +109,9 @@ init_forbid_extra = true
|
|
|
108
109
|
init_typed = true
|
|
109
110
|
warn_required_dynamic_aliases = true
|
|
110
111
|
|
|
112
|
+
[tool.pyright]
|
|
113
|
+
include = ["typing_checks/"]
|
|
114
|
+
|
|
111
115
|
[tool.pytest]
|
|
112
116
|
python_files = ["test_*.py"]
|
|
113
117
|
addopts = ["--tb", "short", "--cov", "./", "--cov-report", "term-missing:skip-covered"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|