Моя идея: написать что-то подобное, но при попытке не могу понять, как TypeAlias потом будет соответствовать где P, а где RV...
Код: Выделить всё
P = ParamSpec('P')
RV = TypeVar('RV')
CoroutineFunction: TypeAlias = Callable[P, Awaitable[RV]]
Код: Выделить всё
# this is just sample coroutine
async def my_afunc(a: int, b: str) -> bool:
return bool(a or b)
# this is usage example
def some_decorator(afunc: CoroutineFunction[[int, str], bool]):
...
# this should handle type checking correctly,
# and warn me if I change the return value type for my_afunc
smth = some_decorator(my_afunc)
Подробнее здесь: https://stackoverflow.com/questions/790 ... type-alias