From a04fb9648f01a45e5f79653526b5d8033290348d Mon Sep 17 00:00:00 2001 From: anthony sottile <103459774+asottile-sentry@users.noreply.github.com> Date: Thu, 13 Jun 2024 17:41:52 -0400 Subject: [PATCH] cache's version can be Any (#14) matches the annotation with default_key_func in practice, we use a hexdigest for cache versioning which is forbidden by int but works fine at runtime Co-authored-by: Anthony Sottile --- django-stubs/core/cache/backends/base.pyi | 62 +++++++++++------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/django-stubs/core/cache/backends/base.pyi b/django-stubs/core/cache/backends/base.pyi index c87be3333..91f441f02 100644 --- a/django-stubs/core/cache/backends/base.pyi +++ b/django-stubs/core/cache/backends/base.pyi @@ -20,50 +20,50 @@ class BaseCache: _max_entries: int _cull_frequency: int key_prefix: str - version: int + version: Any key_func: Callable def __init__(self, params: dict[str, Any]) -> None: ... def get_backend_timeout(self, timeout: float | None = ...) -> float | None: ... - def make_key(self, key: Any, version: int | None = None) -> str: ... + def make_key(self, key: Any, version: Any | None = None) -> str: ... def validate_key(self, key: Any) -> None: ... - def make_and_validate_key(self, key: Any, version: int | None = None) -> str: ... - def add(self, key: Any, value: Any, timeout: float | None = ..., version: int | None = None) -> bool: ... - async def aadd(self, key: Any, value: Any, timeout: float | None = ..., version: int | None = None) -> bool: ... - def get(self, key: Any, default: Any | None = None, version: int | None = None) -> Any: ... - async def aget(self, key: Any, default: Any | None = None, version: int | None = None) -> Any: ... - def set(self, key: Any, value: Any, timeout: float | None = ..., version: int | None = None) -> None: ... - async def aset(self, key: Any, value: Any, timeout: float | None = ..., version: int | None = None) -> None: ... - def touch(self, key: Any, timeout: float | None = ..., version: int | None = None) -> bool: ... - async def atouch(self, key: Any, timeout: float | None = ..., version: int | None = None) -> bool: ... - def delete(self, key: Any, version: int | None = None) -> bool: ... - async def adelete(self, key: Any, version: int | None = None) -> bool: ... - def get_many(self, keys: Iterable[Any], version: int | None = None) -> dict[Any, Any]: ... - async def aget_many(self, keys: Iterable[Any], version: int | None = None) -> dict[Any, Any]: ... + def make_and_validate_key(self, key: Any, version: Any | None = None) -> str: ... + def add(self, key: Any, value: Any, timeout: float | None = ..., version: Any | None = None) -> bool: ... + async def aadd(self, key: Any, value: Any, timeout: float | None = ..., version: Any | None = None) -> bool: ... + def get(self, key: Any, default: Any | None = None, version: Any | None = None) -> Any: ... + async def aget(self, key: Any, default: Any | None = None, version: Any | None = None) -> Any: ... + def set(self, key: Any, value: Any, timeout: float | None = ..., version: Any | None = None) -> None: ... + async def aset(self, key: Any, value: Any, timeout: float | None = ..., version: Any | None = None) -> None: ... + def touch(self, key: Any, timeout: float | None = ..., version: Any | None = None) -> bool: ... + async def atouch(self, key: Any, timeout: float | None = ..., version: Any | None = None) -> bool: ... + def delete(self, key: Any, version: Any | None = None) -> bool: ... + async def adelete(self, key: Any, version: Any | None = None) -> bool: ... + def get_many(self, keys: Iterable[Any], version: Any | None = None) -> dict[Any, Any]: ... + async def aget_many(self, keys: Iterable[Any], version: Any | None = None) -> dict[Any, Any]: ... def get_or_set( - self, key: Any, default: Any | None, timeout: float | None = ..., version: int | None = None + self, key: Any, default: Any | None, timeout: float | None = ..., version: Any | None = None ) -> Any | None: ... async def aget_or_set( - self, key: Any, default: Any | None, timeout: float | None = ..., version: int | None = None + self, key: Any, default: Any | None, timeout: float | None = ..., version: Any | None = None ) -> Any | None: ... - def has_key(self, key: Any, version: int | None = None) -> bool: ... - async def ahas_key(self, key: Any, version: int | None = None) -> bool: ... - def incr(self, key: Any, delta: int = 1, version: int | None = None) -> int: ... - async def aincr(self, key: Any, delta: int = 1, version: int | None = None) -> int: ... - def decr(self, key: Any, delta: int = 1, version: int | None = None) -> int: ... - async def adecr(self, key: Any, delta: int = 1, version: int | None = None) -> int: ... + def has_key(self, key: Any, version: Any | None = None) -> bool: ... + async def ahas_key(self, key: Any, version: Any | None = None) -> bool: ... + def incr(self, key: Any, delta: int = 1, version: Any | None = None) -> int: ... + async def aincr(self, key: Any, delta: int = 1, version: Any | None = None) -> int: ... + def decr(self, key: Any, delta: int = 1, version: Any | None = None) -> int: ... + async def adecr(self, key: Any, delta: int = 1, version: Any | None = None) -> int: ... def __contains__(self, key: Any) -> bool: ... - def set_many(self, data: dict[Any, Any], timeout: float | None = ..., version: int | None = None) -> list[Any]: ... + def set_many(self, data: dict[Any, Any], timeout: float | None = ..., version: Any | None = None) -> list[Any]: ... async def aset_many( - self, data: dict[Any, Any], timeout: float | None = ..., version: int | None = None + self, data: dict[Any, Any], timeout: float | None = ..., version: Any | None = None ) -> list[Any]: ... - def delete_many(self, keys: Iterable[Any], version: int | None = None) -> None: ... - async def adelete_many(self, keys: Iterable[Any], version: int | None = None) -> None: ... + def delete_many(self, keys: Iterable[Any], version: Any | None = None) -> None: ... + async def adelete_many(self, keys: Iterable[Any], version: Any | None = None) -> None: ... def clear(self) -> None: ... async def aclear(self) -> None: ... - def incr_version(self, key: Any, delta: int = 1, version: int | None = None) -> int: ... - async def aincr_version(self, key: Any, delta: int = 1, version: int | None = None) -> int: ... - def decr_version(self, key: Any, delta: int = 1, version: int | None = None) -> int: ... - async def adecr_version(self, key: Any, delta: int = 1, version: int | None = None) -> int: ... + def incr_version(self, key: Any, delta: int = 1, version: Any | None = None) -> int: ... + async def aincr_version(self, key: Any, delta: int = 1, version: Any | None = None) -> int: ... + def decr_version(self, key: Any, delta: int = 1, version: Any | None = None) -> int: ... + async def adecr_version(self, key: Any, delta: int = 1, version: Any | None = None) -> int: ... def close(self, **kwargs: Any) -> None: ... async def aclose(self, **kwargs: Any) -> None: ...