From 557d3d1da2f884055b386d258a86a0b7be25362b Mon Sep 17 00:00:00 2001 From: Hristo Kapanakov Date: Mon, 28 Jul 2025 18:17:44 +0300 Subject: [PATCH] Fix type hints --- mealie/routes/auth/auth_cache.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mealie/routes/auth/auth_cache.py b/mealie/routes/auth/auth_cache.py index 6e3ec1b16..3c4e50d63 100644 --- a/mealie/routes/auth/auth_cache.py +++ b/mealie/routes/auth/auth_cache.py @@ -1,10 +1,11 @@ import time +from typing import Any class AuthCache: - def __init__(self, threshold: int = 500, default_timeout: int = 300): + def __init__(self, threshold: int = 500, default_timeout: float = 300): self.default_timeout = default_timeout - self._cache = {} + self._cache: dict[str, tuple[float, Any]] = {} self.clear = self._cache.clear self._threshold = threshold @@ -18,14 +19,14 @@ class AuthCache: for key in toremove: self._cache.pop(key, None) - def _normalize_timeout(self, timeout: int): + def _normalize_timeout(self, timeout: float | None) -> float: if timeout is None: timeout = self.default_timeout if timeout > 0: timeout = time.time() + timeout return timeout - async def get(self, key: str): + async def get(self, key: str) -> Any: try: expires, value = self._cache[key] if expires == 0 or expires > time.time(): @@ -33,16 +34,16 @@ class AuthCache: except KeyError: return None - async def set(self, key: str, value: any, timeout: int = None): + async def set(self, key: str, value: Any, timeout: float | None = None) -> bool: expires = self._normalize_timeout(timeout) self._prune() self._cache[key] = (expires, value) return True - async def delete(self, key: str): + async def delete(self, key: str) -> bool: return self._cache.pop(key, None) is not None - async def has(self, key: str): + async def has(self, key: str) -> bool: try: expires, value = self._cache[key] return expires == 0 or expires > time.time()