1- from abc import abstractmethod
21from collections .abc import Callable
32from functools import wraps
43from inspect import iscoroutinefunction
5- from typing import Any , Protocol , runtime_checkable
4+ from typing import Any
65
76from injection ._core .common .asynchronous import Caller
87from injection ._core .module import Module , mod
98
10- type AsFunctionWrappedType [** P , T ] = type [AsFunctionCallable [P , T ]]
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 ]]
2010
2111
2212def asfunction [** P , T ](
@@ -29,8 +19,8 @@ def asfunction[**P, T](
2919 module = module or mod ()
3020
3121 def decorator (wp : AsFunctionWrappedType [P , T ]) -> Callable [P , T ]:
32- fake_method = wp .call .__get__ (NotImplemented )
33- factory : Caller [..., AsFunctionCallable [P , T ]] = module .make_injected_function (
22+ fake_method = wp .__call__ .__get__ (NotImplemented , wp )
23+ factory : Caller [..., Callable [P , T ]] = module .make_injected_function (
3424 wp ,
3525 threadsafe = threadsafe ,
3626 ).__inject_metadata__
@@ -42,14 +32,14 @@ def decorator(wp: AsFunctionWrappedType[P, T]) -> Callable[P, T]:
4232 @wraps (fake_method )
4333 async def wrapper (* args : P .args , ** kwargs : P .kwargs ) -> Any :
4434 self = await factory .acall ()
45- return await self . call (* args , ** kwargs ) # type: ignore[misc]
35+ return await self (* args , ** kwargs ) # type: ignore[misc]
4636
4737 else :
4838
4939 @wraps (fake_method )
5040 def wrapper (* args : P .args , ** kwargs : P .kwargs ) -> T :
5141 self = factory .call ()
52- return self . call (* args , ** kwargs )
42+ return self (* args , ** kwargs )
5343
5444 wrapper .__name__ = wp .__name__
5545 wrapper .__qualname__ = wp .__qualname__
0 commit comments