diff --git a/aiocache/decorators.py b/aiocache/decorators.py index d5cdac5d..7ff69db0 100644 --- a/aiocache/decorators.py +++ b/aiocache/decorators.py @@ -2,6 +2,7 @@ import functools import inspect import logging +from typing import Any, Awaitable, Callable, ParamSpec, TypeVar from aiocache.base import SENTINEL from aiocache.factory import Cache, caches @@ -9,6 +10,9 @@ logger = logging.getLogger(__name__) +P = ParamSpec("P") +T = TypeVar("T", bound=Any) + class cached: """ @@ -83,7 +87,7 @@ def __init__( self._plugins = plugins self._kwargs = kwargs - def __call__(self, f): + def __call__(self, f: Callable[P, Awaitable[T]]) -> Callable[P, Awaitable[T]]: if self.alias: self.cache = caches.get(self.alias) for arg in ("serializer", "namespace", "plugins"): @@ -99,7 +103,7 @@ def __call__(self, f): ) @functools.wraps(f) - async def wrapper(*args, **kwargs): + async def wrapper(*args: P.args, **kwargs: P.kwargs) -> T: return await self.decorator(f, *args, **kwargs) wrapper.cache = self.cache