From 71a77f6b39b06d341afb6f6e31c53b4ab4ad0e34 Mon Sep 17 00:00:00 2001 From: Ivan Moiseev Date: Sun, 30 Oct 2022 11:03:16 +0400 Subject: [PATCH] fix: request and response type hints --- fastapi_cache/decorator.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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():