python-injection 0.16.0__tar.gz → 0.17.1__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.16.0 → python_injection-0.17.1}/PKG-INFO +1 -1
- python_injection-0.17.1/injection/ext/fastapi.py +44 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/pyproject.toml +1 -1
- python_injection-0.16.0/injection/integrations/fastapi.py +0 -27
- {python_injection-0.16.0 → python_injection-0.17.1}/.gitignore +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/README.md +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/__init__.py +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/__init__.pyi +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/_core/__init__.py +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/_core/common/__init__.py +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/_core/common/asynchronous.py +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/_core/common/event.py +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/_core/common/invertible.py +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/_core/common/key.py +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/_core/common/lazy.py +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/_core/common/type.py +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/_core/descriptors.py +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/_core/injectables.py +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/_core/module.py +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/_core/scope.py +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/_core/slots.py +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/exceptions.py +0 -0
- {python_injection-0.16.0/injection/integrations → python_injection-0.17.1/injection/ext}/__init__.py +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/py.typed +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/testing/__init__.py +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/testing/__init__.pyi +0 -0
- {python_injection-0.16.0 → python_injection-0.17.1}/injection/utils.py +0 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
from types import GenericAlias
|
2
|
+
from typing import TYPE_CHECKING, Annotated, Any, TypeAliasType
|
3
|
+
|
4
|
+
from fastapi import Depends
|
5
|
+
|
6
|
+
from injection import Module, mod
|
7
|
+
|
8
|
+
__all__ = ("Inject",)
|
9
|
+
|
10
|
+
|
11
|
+
class FastAPIInject:
|
12
|
+
__slots__ = ()
|
13
|
+
|
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
|
+
|
24
|
+
async def getter() -> T:
|
25
|
+
return await lazy_instance
|
26
|
+
|
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
|
@@ -1,27 +0,0 @@
|
|
1
|
-
from types import GenericAlias
|
2
|
-
from typing import Any, TypeAliasType
|
3
|
-
|
4
|
-
from fastapi import Depends
|
5
|
-
|
6
|
-
from injection import Module, mod
|
7
|
-
|
8
|
-
__all__ = ("Inject",)
|
9
|
-
|
10
|
-
|
11
|
-
def Inject[T]( # noqa: N802
|
12
|
-
cls: type[T] | TypeAliasType | GenericAlias,
|
13
|
-
/,
|
14
|
-
default: T = NotImplemented,
|
15
|
-
module: Module | None = None,
|
16
|
-
) -> Any:
|
17
|
-
"""
|
18
|
-
Declare a FastAPI dependency with `python-injection`.
|
19
|
-
"""
|
20
|
-
|
21
|
-
module = module or mod()
|
22
|
-
lazy_instance = module.aget_lazy_instance(cls, default)
|
23
|
-
|
24
|
-
async def getter() -> T:
|
25
|
-
return await lazy_instance
|
26
|
-
|
27
|
-
return Depends(getter, use_cache=False)
|
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
|
{python_injection-0.16.0/injection/integrations → python_injection-0.17.1/injection/ext}/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|