Merge pull request #93 from Mrreadiness/feat/type-hints-covering

Feat/type hints covering
This commit is contained in:
long2ice
2022-11-04 08:51:21 +08:00
committed by GitHub
10 changed files with 99 additions and 68 deletions

View File

@@ -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,11 +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") in ("no-store", "no-cache")
) or not FastAPICache.get_enable():