python-injection 0.17.0__py3-none-any.whl → 0.17.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/ext/fastapi.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
from types import GenericAlias
|
2
|
-
from typing import Any, TypeAliasType
|
2
|
+
from typing import TYPE_CHECKING, Annotated, Any, TypeAliasType
|
3
3
|
|
4
4
|
from fastapi import Depends
|
5
5
|
|
@@ -8,20 +8,37 @@ from injection import Module, mod
|
|
8
8
|
__all__ = ("Inject",)
|
9
9
|
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
/,
|
14
|
-
default: T = NotImplemented,
|
15
|
-
module: Module | None = None,
|
16
|
-
) -> Any:
|
17
|
-
"""
|
18
|
-
Declare a FastAPI dependency with `python-injection`.
|
19
|
-
"""
|
11
|
+
class FastAPIInject:
|
12
|
+
__slots__ = ()
|
20
13
|
|
21
|
-
|
22
|
-
|
14
|
+
def __call__[T](
|
15
|
+
self,
|
16
|
+
cls: type[T] | TypeAliasType | GenericAlias,
|
17
|
+
/,
|
18
|
+
default: T = NotImplemented,
|
19
|
+
module: Module | None = None,
|
20
|
+
) -> Any:
|
21
|
+
module = module or mod()
|
22
|
+
lazy_instance = module.aget_lazy_instance(cls, default)
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
async def getter() -> T:
|
25
|
+
return await lazy_instance
|
26
26
|
|
27
|
-
|
27
|
+
return Depends(getter, use_cache=False)
|
28
|
+
|
29
|
+
def __getitem__(self, params: Any, /) -> Any:
|
30
|
+
if not isinstance(params, tuple):
|
31
|
+
params = (params,)
|
32
|
+
|
33
|
+
iter_params = iter(params)
|
34
|
+
cls = next(iter_params)
|
35
|
+
return Annotated[cls, self(cls), *iter_params]
|
36
|
+
|
37
|
+
|
38
|
+
if TYPE_CHECKING:
|
39
|
+
type Inject[T, *Args] = Annotated[T, Depends(), *Args]
|
40
|
+
|
41
|
+
else:
|
42
|
+
Inject = FastAPIInject()
|
43
|
+
|
44
|
+
del FastAPIInject
|
@@ -17,9 +17,9 @@ injection/_core/common/key.py,sha256=ghkZD-Y8Moz6SEPNgMh3xgsZUjDVq-XYAmXaCu5VuCA
|
|
17
17
|
injection/_core/common/lazy.py,sha256=6xh5h0lmaNvl32V0WoX4VCTsNJ3zUJdWVqpLJ_YeIIU,1363
|
18
18
|
injection/_core/common/type.py,sha256=SCDtmBv9qFvEf5o5tTgCuwMDfuo1fgjSW0bUqA8ACis,2251
|
19
19
|
injection/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
20
|
-
injection/ext/fastapi.py,sha256=
|
20
|
+
injection/ext/fastapi.py,sha256=1TSVd5zOdpugk4PtWK13t4V-CsfERBlt6ZwG_ML2kuk,1013
|
21
21
|
injection/testing/__init__.py,sha256=SiImXDd0-DO1a8S5nbUQRtgDX8iaU_nHcp8DdqwtD2M,896
|
22
22
|
injection/testing/__init__.pyi,sha256=iOii0i9F5n7znltGeGQYI2KXC_if9SAogLh1h03yx-0,540
|
23
|
-
python_injection-0.17.
|
24
|
-
python_injection-0.17.
|
25
|
-
python_injection-0.17.
|
23
|
+
python_injection-0.17.1.dist-info/METADATA,sha256=KHngttE3jix1NZK_YgGmDSZOd6JXDWMb0UygpY5tRpM,3199
|
24
|
+
python_injection-0.17.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
25
|
+
python_injection-0.17.1.dist-info/RECORD,,
|
File without changes
|