fix: request and response type hints

This commit is contained in:
Ivan Moiseev
2022-10-30 11:03:16 +04:00
parent e555d5e9be
commit 71a77f6b39

View File

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