[FEATURE] typing should be supported in @xn
bashirmindee opened this issue · 2 comments
@bashirmindee can you provide a short description so we can keep track of the iterations plz ?
This thread provides a temporary solution:
https://blog.whtsky.me/tech/2021/decorator-type-gymnastics-in-python/
from typing import TypeVar, Callable, Awaitable, overload
A = TypeVar('A')
B = TypeVar('B')
C = TypeVar('C')
D = TypeVar('D')
E = TypeVar('E')
RV = TypeVar('RV')
@overload
def sync_to_async(f: Callable[[A], RV]) -> Callable[[A], Awaitable[RV]]:
...
@overload
def sync_to_async(f: Callable[[A, B], RV]) -> Callable[[A, B], Awaitable[RV]]:
...
@overload
def sync_to_async(f: Callable[[A, B, C], RV]) -> Callable[[A, B, C], Awaitable[RV]]:
...
@overload
def sync_to_async(f: Callable[[A, B, C, D], RV]) -> Callable[[A, B, C, D], Awaitable[RV]]:
...
@overload
def sync_to_async(f: Callable[[A, B, C, D, E], RV]) -> Callable[[A, B, C, D, E], Awaitable[RV]]:
...
def sync_to_async(f):
async def wrapper(*args, **kwargs):
return f(*args, **kwargs)
return wrapper
@sync_to_async
def two_sum(a: int, b: int) -> int:
return a + b
@sync_to_async
def do_log(content: str) -> None:
print(content)
reveal_type(two_sum) # Revealed type is 'def (builtins.int*, builtins.int*) -> typing.Awaitable[builtins.int*]'
reveal_type(do_log) # Revealed type is 'def (builtins.str*) -> typing.Awaitable[None]'