python-injection 0.19.0__tar.gz → 0.19.2__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.19.0 → python_injection-0.19.2}/PKG-INFO +1 -1
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/__init__.pyi +3 -2
- python_injection-0.19.2/injection/_core/asfunction.py +59 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/pyproject.toml +1 -1
- python_injection-0.19.0/injection/_core/asfunction.py +0 -47
- {python_injection-0.19.0 → python_injection-0.19.2}/.gitignore +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/LICENSE +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/README.md +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/__init__.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/_core/__init__.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/_core/common/__init__.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/_core/common/asynchronous.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/_core/common/event.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/_core/common/invertible.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/_core/common/key.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/_core/common/lazy.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/_core/common/threading.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/_core/common/type.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/_core/descriptors.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/_core/injectables.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/_core/module.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/_core/scope.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/_core/slots.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/entrypoint.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/exceptions.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/ext/__init__.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/ext/fastapi.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/ext/fastapi.pyi +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/loaders.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/py.typed +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/testing/__init__.py +0 -0
- {python_injection-0.19.0 → python_injection-0.19.2}/injection/testing/__init__.pyi +0 -0
@@ -5,6 +5,7 @@ from enum import Enum
|
|
5
5
|
from logging import Logger
|
6
6
|
from typing import Any, Final, Protocol, Self, final, overload, runtime_checkable
|
7
7
|
|
8
|
+
from ._core.asfunction import AsFunctionWrappedType as _AsFunctionWrappedType
|
8
9
|
from ._core.common.invertible import Invertible as _Invertible
|
9
10
|
from ._core.common.type import InputType as _InputType
|
10
11
|
from ._core.common.type import TypeInfo as _TypeInfo
|
@@ -32,7 +33,7 @@ singleton = __MODULE.singleton
|
|
32
33
|
|
33
34
|
@overload
|
34
35
|
def asfunction[**P, T](
|
35
|
-
wrapped:
|
36
|
+
wrapped: _AsFunctionWrappedType[P, T],
|
36
37
|
/,
|
37
38
|
*,
|
38
39
|
module: Module = ...,
|
@@ -45,7 +46,7 @@ def asfunction[**P, T](
|
|
45
46
|
*,
|
46
47
|
module: Module = ...,
|
47
48
|
threadsafe: bool | None = ...,
|
48
|
-
) -> Callable[[
|
49
|
+
) -> Callable[[_AsFunctionWrappedType[P, T]], Callable[P, T]]: ...
|
49
50
|
@asynccontextmanager
|
50
51
|
def adefine_scope(
|
51
52
|
name: str,
|
@@ -0,0 +1,59 @@
|
|
1
|
+
from abc import abstractmethod
|
2
|
+
from collections.abc import Callable
|
3
|
+
from functools import wraps
|
4
|
+
from inspect import iscoroutinefunction
|
5
|
+
from types import MethodType
|
6
|
+
from typing import Any, Protocol, runtime_checkable
|
7
|
+
|
8
|
+
from injection._core.common.asynchronous import Caller
|
9
|
+
from injection._core.module import Module, mod
|
10
|
+
|
11
|
+
type AsFunctionWrappedType[**P, T] = type[AsFunctionCallable[P, T]]
|
12
|
+
|
13
|
+
|
14
|
+
@runtime_checkable
|
15
|
+
class AsFunctionCallable[**P, T](Protocol):
|
16
|
+
__slots__ = ()
|
17
|
+
|
18
|
+
@abstractmethod
|
19
|
+
def call(self, *args: P.args, **kwargs: P.kwargs) -> T:
|
20
|
+
raise NotImplementedError
|
21
|
+
|
22
|
+
|
23
|
+
def asfunction[**P, T](
|
24
|
+
wrapped: AsFunctionWrappedType[P, T] | None = None,
|
25
|
+
/,
|
26
|
+
*,
|
27
|
+
module: Module | None = None,
|
28
|
+
threadsafe: bool | None = None,
|
29
|
+
) -> Any:
|
30
|
+
module = module or mod()
|
31
|
+
|
32
|
+
def decorator(wp: AsFunctionWrappedType[P, T]) -> Callable[P, T]:
|
33
|
+
fake_method = MethodType(wp.call, NotImplemented)
|
34
|
+
factory: Caller[..., AsFunctionCallable[P, T]] = module.make_injected_function(
|
35
|
+
wp,
|
36
|
+
threadsafe=threadsafe,
|
37
|
+
).__inject_metadata__
|
38
|
+
|
39
|
+
wrapper: Callable[P, T]
|
40
|
+
|
41
|
+
if iscoroutinefunction(fake_method):
|
42
|
+
|
43
|
+
@wraps(fake_method)
|
44
|
+
async def wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
|
45
|
+
self = await factory.acall()
|
46
|
+
return await self.call(*args, **kwargs) # type: ignore[misc]
|
47
|
+
|
48
|
+
else:
|
49
|
+
|
50
|
+
@wraps(fake_method)
|
51
|
+
def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
|
52
|
+
self = factory.call()
|
53
|
+
return self.call(*args, **kwargs)
|
54
|
+
|
55
|
+
wrapper.__name__ = wp.__name__
|
56
|
+
wrapper.__qualname__ = wp.__qualname__
|
57
|
+
return wrapper
|
58
|
+
|
59
|
+
return decorator(wrapped) if wrapped else decorator
|
@@ -1,47 +0,0 @@
|
|
1
|
-
from collections.abc import Callable
|
2
|
-
from functools import wraps
|
3
|
-
from inspect import iscoroutinefunction
|
4
|
-
from typing import Any
|
5
|
-
|
6
|
-
from injection._core.common.asynchronous import Caller
|
7
|
-
from injection._core.module import Module, mod
|
8
|
-
|
9
|
-
|
10
|
-
def asfunction[**P, T](
|
11
|
-
wrapped: type[Callable[P, T]] | None = None,
|
12
|
-
/,
|
13
|
-
*,
|
14
|
-
module: Module | None = None,
|
15
|
-
threadsafe: bool | None = None,
|
16
|
-
) -> Any:
|
17
|
-
module = module or mod()
|
18
|
-
|
19
|
-
def decorator(wp: type[Callable[P, T]]) -> Callable[P, T]:
|
20
|
-
get_method = wp.__call__.__get__
|
21
|
-
method = get_method(NotImplemented)
|
22
|
-
factory: Caller[..., Callable[P, T]] = module.make_injected_function(
|
23
|
-
wp,
|
24
|
-
threadsafe=threadsafe,
|
25
|
-
).__inject_metadata__
|
26
|
-
|
27
|
-
wrapper: Callable[P, T]
|
28
|
-
|
29
|
-
if iscoroutinefunction(method):
|
30
|
-
|
31
|
-
@wraps(method)
|
32
|
-
async def wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
|
33
|
-
self = await factory.acall()
|
34
|
-
return await get_method(self)(*args, **kwargs)
|
35
|
-
|
36
|
-
else:
|
37
|
-
|
38
|
-
@wraps(method)
|
39
|
-
def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
|
40
|
-
self = factory.call()
|
41
|
-
return get_method(self)(*args, **kwargs)
|
42
|
-
|
43
|
-
wrapper.__name__ = wp.__name__
|
44
|
-
wrapper.__qualname__ = wp.__qualname__
|
45
|
-
return wrapper
|
46
|
-
|
47
|
-
return decorator(wrapped) if wrapped else decorator
|
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
|
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
|