Define keybuilder protocol

This lets others create key builders that are type checked fully.
This commit is contained in:
Martijn Pieters
2023-04-27 16:24:22 +01:00
parent d4cd787527
commit 255f40117b
3 changed files with 29 additions and 6 deletions

21
fastapi_cache/types.py Normal file
View File

@@ -0,0 +1,21 @@
from typing import Any, Awaitable, Callable, Optional, Protocol, Union
from starlette.requests import Request
from starlette.responses import Response
_Func = Callable[..., Any]
class KeyBuilder(Protocol):
def __call__(
self,
_function: _Func,
_namespace: str = ...,
*,
request: Optional[Request] = ...,
response: Optional[Response] = ...,
args: Optional[tuple[Any, ...]] = ...,
kwargs: Optional[dict[str, Any]] = ...,
) -> Union[Awaitable[str], str]:
...