|
| 1 | +from abc import abstractmethod |
1 | 2 | from collections.abc import Callable
|
2 | 3 | from functools import wraps
|
3 | 4 | from inspect import iscoroutinefunction
|
4 |
| -from typing import Any |
| 5 | +from typing import Any, Protocol, runtime_checkable |
5 | 6 |
|
6 | 7 | from injection._core.common.asynchronous import Caller
|
7 | 8 | from injection._core.module import Module, mod
|
8 | 9 |
|
| 10 | +type AsFunctionWrappedType[**P, T] = type[_Callable[P, T]] |
| 11 | + |
| 12 | + |
| 13 | +@runtime_checkable |
| 14 | +class _Callable[**P, T](Protocol): |
| 15 | + __slots__ = () |
| 16 | + |
| 17 | + @abstractmethod |
| 18 | + def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T: |
| 19 | + raise NotImplementedError |
| 20 | + |
9 | 21 |
|
10 | 22 | def asfunction[**P, T](
|
11 |
| - wrapped: type[Callable[P, T]] | None = None, |
| 23 | + wrapped: AsFunctionWrappedType[P, T] | None = None, |
12 | 24 | /,
|
13 | 25 | *,
|
14 | 26 | module: Module | None = None,
|
15 | 27 | threadsafe: bool | None = None,
|
16 | 28 | ) -> Any:
|
17 | 29 | module = module or mod()
|
18 | 30 |
|
19 |
| - def decorator(wp: type[Callable[P, T]]) -> Callable[P, T]: |
| 31 | + def decorator(wp: AsFunctionWrappedType[P, T]) -> Callable[P, T]: |
20 | 32 | get_method = wp.__call__.__get__
|
21 | 33 | method = get_method(NotImplemented)
|
22 | 34 | factory: Caller[..., Callable[P, T]] = module.make_injected_function(
|
|
0 commit comments