python-injection 0.16.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.
@@ -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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-injection
3
- Version: 0.16.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
@@ -16,10 +16,10 @@ injection/_core/common/invertible.py,sha256=gA_vw5nBjgp_w9MrDK5jMO8lhuOQWON8BbPp
16
16
  injection/_core/common/key.py,sha256=ghkZD-Y8Moz6SEPNgMh3xgsZUjDVq-XYAmXaCu5VuCA,80
17
17
  injection/_core/common/lazy.py,sha256=6xh5h0lmaNvl32V0WoX4VCTsNJ3zUJdWVqpLJ_YeIIU,1363
18
18
  injection/_core/common/type.py,sha256=SCDtmBv9qFvEf5o5tTgCuwMDfuo1fgjSW0bUqA8ACis,2251
19
- injection/integrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
- injection/integrations/fastapi.py,sha256=YHSs85_3m6TUVtOwUcV157b3UZJQIw_aXWAg199a-YE,594
19
+ injection/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
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.16.0.dist-info/METADATA,sha256=g8st7-_QqRHhi8eS_vCYHWx8AppVvczjhAb3Qw0owRE,3199
24
- python_injection-0.16.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
25
- python_injection-0.16.0.dist-info/RECORD,,
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,,
@@ -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