feat: add more asserts for FastAPICache init

This commit is contained in:
Ivan Moiseev
2022-10-22 21:05:43 +04:00
parent 4c6abcf786
commit 68ef94f2db

View File

@@ -40,7 +40,8 @@ class FastAPICache:
return cls._backend return cls._backend
@classmethod @classmethod
def get_prefix(cls) -> Optional[str]: def get_prefix(cls) -> str:
assert cls._prefix, "You must call init first!" # nosec: B101
return cls._prefix return cls._prefix
@classmethod @classmethod
@@ -48,11 +49,13 @@ class FastAPICache:
return cls._expire return cls._expire
@classmethod @classmethod
def get_coder(cls) -> Optional[Type[Coder]]: def get_coder(cls) -> Type[Coder]:
assert cls._coder, "You must call init first!" # nosec: B101
return cls._coder return cls._coder
@classmethod @classmethod
def get_key_builder(cls) -> Optional[Callable]: def get_key_builder(cls) -> Callable:
assert cls._key_builder, "You must call init first!" # nosec: B101
return cls._key_builder return cls._key_builder
@classmethod @classmethod
@@ -61,5 +64,6 @@ class FastAPICache:
@classmethod @classmethod
async def clear(cls, namespace: Optional[str] = None, key: Optional[str] = None) -> int: async def clear(cls, namespace: Optional[str] = None, key: Optional[str] = None) -> int:
assert cls._backend and cls._prefix, "You must call init first!" # nosec: B101
namespace = cls._prefix + (":" + namespace if namespace else "") namespace = cls._prefix + (":" + namespace if namespace else "")
return await cls._backend.clear(namespace, key) return await cls._backend.clear(namespace, key)