diff --git a/fastapi_cache/decorator.py b/fastapi_cache/decorator.py index be50d30..8a5e0a6 100644 --- a/fastapi_cache/decorator.py +++ b/fastapi_cache/decorator.py @@ -1,7 +1,8 @@ import inspect import sys from functools import wraps -from typing import Any, Awaitable, Callable, Optional, TypeVar +from typing import Any, Awaitable, Callable, Optional, TypeVar, Type + if sys.version_info >= (3, 10): from typing import ParamSpec else: @@ -21,7 +22,7 @@ R = TypeVar("R") def cache( expire: Optional[int] = None, - coder: Optional[Coder] = None, + coder: Optional[Type[Coder]] = None, key_builder: Optional[Callable[..., Any]] = None, namespace: Optional[str] = "", ) -> Callable[[Callable[P, Awaitable[R]]], Callable[P, Awaitable[R]]]: @@ -92,10 +93,9 @@ def cache( # see above why we have to await even although caller also awaits. return await run_in_threadpool(func, *args, **kwargs) - copy_kwargs = kwargs.copy() - request = copy_kwargs.pop("request", None) - response = copy_kwargs.pop("response", None) + request: Optional[Request] = copy_kwargs.pop("request", None) + response: Optional[Response] = copy_kwargs.pop("response", None) if ( request and request.headers.get("Cache-Control") == "no-store" ) or not FastAPICache.get_enable():