python-injection 0.19.8__py3-none-any.whl → 0.21.0__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/_core/asfunction.py +6 -16
- injection/_core/common/type.py +3 -5
- {python_injection-0.19.8.dist-info → python_injection-0.21.0.dist-info}/METADATA +3 -2
- {python_injection-0.19.8.dist-info → python_injection-0.21.0.dist-info}/RECORD +6 -6
- {python_injection-0.19.8.dist-info → python_injection-0.21.0.dist-info}/WHEEL +0 -0
- {python_injection-0.19.8.dist-info → python_injection-0.21.0.dist-info}/licenses/LICENSE +0 -0
injection/_core/asfunction.py
CHANGED
@@ -1,22 +1,12 @@
|
|
1
|
-
from abc import abstractmethod
|
2
1
|
from collections.abc import Callable
|
3
2
|
from functools import wraps
|
4
3
|
from inspect import iscoroutinefunction
|
5
|
-
from typing import Any
|
4
|
+
from typing import Any
|
6
5
|
|
7
6
|
from injection._core.common.asynchronous import Caller
|
8
7
|
from injection._core.module import Module, mod
|
9
8
|
|
10
|
-
type AsFunctionWrappedType[**P, T] = type[
|
11
|
-
|
12
|
-
|
13
|
-
@runtime_checkable
|
14
|
-
class AsFunctionCallable[**P, T](Protocol):
|
15
|
-
__slots__ = ()
|
16
|
-
|
17
|
-
@abstractmethod
|
18
|
-
def call(self, *args: P.args, **kwargs: P.kwargs) -> T:
|
19
|
-
raise NotImplementedError
|
9
|
+
type AsFunctionWrappedType[**P, T] = type[Callable[P, T]]
|
20
10
|
|
21
11
|
|
22
12
|
def asfunction[**P, T](
|
@@ -29,8 +19,8 @@ def asfunction[**P, T](
|
|
29
19
|
module = module or mod()
|
30
20
|
|
31
21
|
def decorator(wp: AsFunctionWrappedType[P, T]) -> Callable[P, T]:
|
32
|
-
fake_method = wp.
|
33
|
-
factory: Caller[...,
|
22
|
+
fake_method = wp.__call__.__get__(NotImplemented, wp)
|
23
|
+
factory: Caller[..., Callable[P, T]] = module.make_injected_function(
|
34
24
|
wp,
|
35
25
|
threadsafe=threadsafe,
|
36
26
|
).__inject_metadata__
|
@@ -42,14 +32,14 @@ def asfunction[**P, T](
|
|
42
32
|
@wraps(fake_method)
|
43
33
|
async def wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
|
44
34
|
self = await factory.acall()
|
45
|
-
return await self
|
35
|
+
return await self(*args, **kwargs) # type: ignore[misc]
|
46
36
|
|
47
37
|
else:
|
48
38
|
|
49
39
|
@wraps(fake_method)
|
50
40
|
def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
|
51
41
|
self = factory.call()
|
52
|
-
return self
|
42
|
+
return self(*args, **kwargs)
|
53
43
|
|
54
44
|
wrapper.__name__ = wp.__name__
|
55
45
|
wrapper.__qualname__ = wp.__qualname__
|
injection/_core/common/type.py
CHANGED
@@ -4,10 +4,10 @@ from collections.abc import (
|
|
4
4
|
AsyncIterator,
|
5
5
|
Awaitable,
|
6
6
|
Callable,
|
7
|
+
Collection,
|
7
8
|
Generator,
|
8
9
|
Iterable,
|
9
10
|
Iterator,
|
10
|
-
Sequence,
|
11
11
|
)
|
12
12
|
from inspect import isfunction
|
13
13
|
from types import GenericAlias, UnionType
|
@@ -27,15 +27,13 @@ type TypeInfo[T] = (
|
|
27
27
|
InputType[T]
|
28
28
|
| Callable[..., T]
|
29
29
|
| Callable[..., Awaitable[T]]
|
30
|
-
|
|
30
|
+
| Collection[TypeInfo[T]]
|
31
31
|
)
|
32
32
|
|
33
33
|
|
34
34
|
def get_return_types(*args: TypeInfo[Any]) -> Iterator[InputType[Any]]:
|
35
35
|
for arg in args:
|
36
|
-
if isinstance(arg,
|
37
|
-
isinstance(arg, type | str) or isinstance(get_origin(arg), type)
|
38
|
-
):
|
36
|
+
if isinstance(arg, Collection):
|
39
37
|
inner_args = arg
|
40
38
|
|
41
39
|
elif isfunction(arg) and (return_type := get_return_hint(arg)):
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: python-injection
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.21.0
|
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,12 +16,13 @@ Classifier: Programming Language :: Python :: 3
|
|
16
16
|
Classifier: Programming Language :: Python :: 3 :: Only
|
17
17
|
Classifier: Programming Language :: Python :: 3.12
|
18
18
|
Classifier: Programming Language :: Python :: 3.13
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
19
20
|
Classifier: Topic :: Software Development :: Libraries
|
20
21
|
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
21
22
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
22
23
|
Classifier: Topic :: Software Development :: Testing
|
23
24
|
Classifier: Typing :: Typed
|
24
|
-
Requires-Python: <
|
25
|
+
Requires-Python: <3.15,>=3.12
|
25
26
|
Provides-Extra: async
|
26
27
|
Requires-Dist: anyio; extra == 'async'
|
27
28
|
Description-Content-Type: text/markdown
|
@@ -5,7 +5,7 @@ injection/exceptions.py,sha256=v57yMujiq6H_zwwn30A8UYEZX9R9k-bY8FnsdaimPM4,1025
|
|
5
5
|
injection/loaders.py,sha256=gKlJfe9nXCuB8r6j0RF9_2FHC6YplM8GQYsgRqyxYw8,7257
|
6
6
|
injection/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
7
|
injection/_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
|
-
injection/_core/asfunction.py,sha256=
|
8
|
+
injection/_core/asfunction.py,sha256=BIMLoz5iLNbTcdbvWdipA9nupjYI1y2EL2amT8s8FLs,1453
|
9
9
|
injection/_core/descriptors.py,sha256=1OX6JnM8Ux14vW1JSW3FzPgKc2VMTKqJUYBGT3Ypafg,800
|
10
10
|
injection/_core/injectables.py,sha256=fxhiGv7qTCbUunhhd6a3ahosFmgznUFsEvqlwxi4gS4,6098
|
11
11
|
injection/_core/module.py,sha256=kUOzW7CYf3oGgVBhwJT1-05UI-HLH2N_E4o17Fyw1g4,32721
|
@@ -18,13 +18,13 @@ injection/_core/common/invertible.py,sha256=gA_vw5nBjgp_w9MrDK5jMO8lhuOQWON8BbPp
|
|
18
18
|
injection/_core/common/key.py,sha256=ghkZD-Y8Moz6SEPNgMh3xgsZUjDVq-XYAmXaCu5VuCA,80
|
19
19
|
injection/_core/common/lazy.py,sha256=hZvz9LhlYxVkD_D8VBAvQmy7YuVaaw075jq0XM0w9_Y,1193
|
20
20
|
injection/_core/common/threading.py,sha256=LR5_wiwZ9_YrcOOKg0qtwbe1YqYdYP57-PAFIe4bknM,415
|
21
|
-
injection/_core/common/type.py,sha256=
|
21
|
+
injection/_core/common/type.py,sha256=w8nH8_OilxR9r9zGNXqIxzMJbrw0uUUMBnpw9NTnkaY,2476
|
22
22
|
injection/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
23
23
|
injection/ext/fastapi.py,sha256=fiy3-mZIIwGcql3Y5ekFX8_7hALzqXP5u40qbtNE73o,1441
|
24
24
|
injection/ext/fastapi.pyi,sha256=HLs7mfruIEFRrN_Xf8oCvSa4qwHWfwm6HHU_KMedXkE,185
|
25
25
|
injection/testing/__init__.py,sha256=bJ7WXBXrw4rHc91AFVFnOwFLWOlpvX9Oh2SnRQ_NESo,919
|
26
26
|
injection/testing/__init__.pyi,sha256=raGsGlxwbz3jkzJwA_5oCIE1emWINjT2UuwzbnqRb-0,577
|
27
|
-
python_injection-0.
|
28
|
-
python_injection-0.
|
29
|
-
python_injection-0.
|
30
|
-
python_injection-0.
|
27
|
+
python_injection-0.21.0.dist-info/METADATA,sha256=KiLbu5XjjCpNwdTIOkwTwZBflYpLPvTVkN8g8rHzX0c,4667
|
28
|
+
python_injection-0.21.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
29
|
+
python_injection-0.21.0.dist-info/licenses/LICENSE,sha256=oC77BOa9kaaQni5rW-Z-ytz3E5h4EVg248BHg9UFgyg,1063
|
30
|
+
python_injection-0.21.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|