python-injection 0.17.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.
Files changed (27) hide show
  1. {python_injection-0.17.0 → python_injection-0.17.1}/PKG-INFO +1 -1
  2. python_injection-0.17.1/injection/ext/fastapi.py +44 -0
  3. {python_injection-0.17.0 → python_injection-0.17.1}/pyproject.toml +1 -1
  4. python_injection-0.17.0/injection/ext/fastapi.py +0 -27
  5. {python_injection-0.17.0 → python_injection-0.17.1}/.gitignore +0 -0
  6. {python_injection-0.17.0 → python_injection-0.17.1}/README.md +0 -0
  7. {python_injection-0.17.0 → python_injection-0.17.1}/injection/__init__.py +0 -0
  8. {python_injection-0.17.0 → python_injection-0.17.1}/injection/__init__.pyi +0 -0
  9. {python_injection-0.17.0 → python_injection-0.17.1}/injection/_core/__init__.py +0 -0
  10. {python_injection-0.17.0 → python_injection-0.17.1}/injection/_core/common/__init__.py +0 -0
  11. {python_injection-0.17.0 → python_injection-0.17.1}/injection/_core/common/asynchronous.py +0 -0
  12. {python_injection-0.17.0 → python_injection-0.17.1}/injection/_core/common/event.py +0 -0
  13. {python_injection-0.17.0 → python_injection-0.17.1}/injection/_core/common/invertible.py +0 -0
  14. {python_injection-0.17.0 → python_injection-0.17.1}/injection/_core/common/key.py +0 -0
  15. {python_injection-0.17.0 → python_injection-0.17.1}/injection/_core/common/lazy.py +0 -0
  16. {python_injection-0.17.0 → python_injection-0.17.1}/injection/_core/common/type.py +0 -0
  17. {python_injection-0.17.0 → python_injection-0.17.1}/injection/_core/descriptors.py +0 -0
  18. {python_injection-0.17.0 → python_injection-0.17.1}/injection/_core/injectables.py +0 -0
  19. {python_injection-0.17.0 → python_injection-0.17.1}/injection/_core/module.py +0 -0
  20. {python_injection-0.17.0 → python_injection-0.17.1}/injection/_core/scope.py +0 -0
  21. {python_injection-0.17.0 → python_injection-0.17.1}/injection/_core/slots.py +0 -0
  22. {python_injection-0.17.0 → python_injection-0.17.1}/injection/exceptions.py +0 -0
  23. {python_injection-0.17.0 → python_injection-0.17.1}/injection/ext/__init__.py +0 -0
  24. {python_injection-0.17.0 → python_injection-0.17.1}/injection/py.typed +0 -0
  25. {python_injection-0.17.0 → python_injection-0.17.1}/injection/testing/__init__.py +0 -0
  26. {python_injection-0.17.0 → python_injection-0.17.1}/injection/testing/__init__.pyi +0 -0
  27. {python_injection-0.17.0 → python_injection-0.17.1}/injection/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-injection
3
- Version: 0.17.0
3
+ Version: 0.17.1
4
4
  Summary: Fast and easy dependency injection framework.
5
5
  Project-URL: Repository, https://github.com/100nm/python-injection
6
6
  Author: remimd
@@ -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
@@ -25,7 +25,7 @@ test = [
25
25
 
26
26
  [project]
27
27
  name = "python-injection"
28
- version = "0.17.0"
28
+ version = "0.17.1"
29
29
  description = "Fast and easy dependency injection framework."
30
30
  license = { text = "MIT" }
31
31
  readme = "README.md"
@@ -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)