From b3def3b71c24780afce1a411d5fcc60ce2ff98d9 Mon Sep 17 00:00:00 2001 From: Thomas Kemmer Date: Sun, 19 Apr 2026 21:40:24 +0200 Subject: [PATCH 1/3] [cachetools] Update to 7.0.* (#15357) --- .../cachetools/@tests/stubtest_allowlist.txt | 2 + stubs/cachetools/METADATA.toml | 2 +- stubs/cachetools/cachetools/__init__.pyi | 127 +++++++++++------- stubs/cachetools/cachetools/keys.pyi | 3 +- 4 files changed, 80 insertions(+), 54 deletions(-) diff --git a/stubs/cachetools/@tests/stubtest_allowlist.txt b/stubs/cachetools/@tests/stubtest_allowlist.txt index b33b7717d7d4..a0bcfbfe73bc 100644 --- a/stubs/cachetools/@tests/stubtest_allowlist.txt +++ b/stubs/cachetools/@tests/stubtest_allowlist.txt @@ -9,6 +9,8 @@ cachetools.LFUCache.__setitem__ cachetools.LRUCache.__delitem__ cachetools.LRUCache.__getitem__ cachetools.LRUCache.__setitem__ +cachetools.RRCache.__delitem__ +cachetools.RRCache.__setitem__ cachetools.TLRUCache.__delitem__ cachetools.TLRUCache.__getitem__ cachetools.TLRUCache.__setitem__ diff --git a/stubs/cachetools/METADATA.toml b/stubs/cachetools/METADATA.toml index 11f301c967c2..3a97ad1d192a 100644 --- a/stubs/cachetools/METADATA.toml +++ b/stubs/cachetools/METADATA.toml @@ -1,2 +1,2 @@ -version = "6.2.*" +version = "7.0.*" upstream-repository = "https://github.com/tkem/cachetools" diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index 6c8d0d8f4500..0e7114f689d5 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -1,23 +1,18 @@ -from _typeshed import IdentityFunction, Unused from collections.abc import Callable, Iterator, MutableMapping, Sequence from contextlib import AbstractContextManager -from threading import Condition -from typing import Any, Generic, Literal, NamedTuple, TypeVar, overload, type_check_only -from typing_extensions import Self, deprecated +from typing import Any, Final, Generic, Literal, NamedTuple, Protocol, TypeVar, overload, type_check_only -__all__ = ("Cache", "FIFOCache", "LFUCache", "LRUCache", "RRCache", "TLRUCache", "TTLCache", "cached", "cachedmethod") +__all__: Final = ("Cache", "FIFOCache", "LFUCache", "LRUCache", "RRCache", "TLRUCache", "TTLCache", "cached", "cachedmethod") __version__: str _KT = TypeVar("_KT") _VT = TypeVar("_VT") +_TT = TypeVar("_TT") _T = TypeVar("_T") _R = TypeVar("_R") class Cache(MutableMapping[_KT, _VT]): - @overload - def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float]) -> None: ... - @overload - def __init__(self, maxsize: float, getsizeof: None = None) -> None: ... + def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = None): ... def __getitem__(self, key: _KT) -> _VT: ... def __setitem__(self, key: _KT, value: _VT) -> None: ... def __delitem__(self, key: _KT) -> None: ... @@ -53,52 +48,57 @@ class RRCache(Cache[_KT, _VT]): def __init__(self, maxsize: float, choice: Callable[[Sequence[_KT]], _KT], getsizeof: Callable[[_VT], float]) -> None: ... @property def choice(self) -> Callable[[Sequence[_KT]], _KT]: ... - def __setitem__(self, key: _KT, value: _VT, cache_setitem: Callable[[Self, _KT, _VT], None] = ...) -> None: ... - def __delitem__(self, key: _KT, cache_delitem: Callable[[Self, _KT], None] = ...) -> None: ... class _TimedCache(Cache[_KT, _VT]): @overload - def __init__(self, maxsize: float, timer: Callable[[], float] = ..., getsizeof: None = None) -> None: ... + def __init__(self, maxsize: float, timer: Callable[[], _TT] = ..., getsizeof: None = None): ... @overload - def __init__(self, maxsize: float, timer: Callable[[], float], getsizeof: Callable[[_VT], float]) -> None: ... + def __init__(self, maxsize: float, timer: Callable[[], _TT], getsizeof: Callable[[_VT], float]): ... @overload - def __init__(self, maxsize: float, timer: Callable[[], float] = ..., *, getsizeof: Callable[[_VT], float]) -> None: ... - @property - def currsize(self) -> float: ... + def __init__(self, maxsize: float, timer: Callable[[], _TT] = ..., *, getsizeof: Callable[[_VT], float]): ... class _Timer: - def __init__(self, timer: Callable[[], float]) -> None: ... - def __call__(self) -> float: ... - def __enter__(self) -> float: ... - def __exit__(self, *exc: Unused) -> None: ... + def __init__(self, timer: Callable[[], _TT]) -> None: ... + def __call__(self) -> Any: ... + def __enter__(self) -> Any: ... + def __exit__(self, *exc: object) -> None: ... + def __getattr__(self, name: str) -> Any: ... @property def timer(self) -> _Timer: ... class TTLCache(_TimedCache[_KT, _VT]): @overload - def __init__(self, maxsize: float, ttl: float, timer: Callable[[], float] = ..., getsizeof: None = None) -> None: ... + def __init__(self, maxsize: float, ttl: Any, timer: Callable[..., _TT] = ..., getsizeof: None = None): ... @overload - def __init__(self, maxsize: float, ttl: float, timer: Callable[[], float], getsizeof: Callable[[_VT], float]) -> None: ... + def __init__(self, maxsize: float, ttl: Any, timer: Callable[..., _TT], getsizeof: Callable[[_VT], float]): ... @overload - def __init__( - self, maxsize: float, ttl: float, timer: Callable[[], float] = ..., *, getsizeof: Callable[[_VT], float] - ) -> None: ... + def __init__(self, maxsize: float, ttl: Any, timer: Callable[..., _TT] = ..., *, getsizeof: Callable[[_VT], float]): ... @property - def ttl(self) -> float: ... - def expire(self, time: float | None = None) -> list[tuple[_KT, _VT]]: ... + def ttl(self) -> Any: ... + def expire(self, time: Any | None = None) -> list[tuple[_KT, _VT]]: ... class TLRUCache(_TimedCache[_KT, _VT]): + @overload + def __init__( + self, maxsize: float, ttu: Callable[[_KT, _VT, _TT], _TT], timer: Callable[..., _TT] = ..., getsizeof: None = None + ): ... + @overload + def __init__( + self, maxsize: float, ttu: Callable[[_KT, _VT, _TT], _TT], timer: Callable[..., _TT], getsizeof: Callable[[_VT], float] + ): ... + @overload def __init__( self, maxsize: float, - ttu: Callable[[_KT, _VT, float], float], - timer: Callable[[], float] = ..., - getsizeof: Callable[[_VT], float] | None = None, - ) -> None: ... + ttu: Callable[[_KT, _VT, _TT], _TT], + timer: Callable[..., _TT] = ..., + *, + getsizeof: Callable[[_VT], float], + ): ... @property - def ttu(self) -> Callable[[_KT, _VT, float], float]: ... - def expire(self, time: float | None = None) -> list[tuple[_KT, _VT]]: ... + def ttu(self) -> Callable[[_KT, _VT, _TT], _TT]: ... + def expire(self, time: Any | None = None) -> list[tuple[_KT, _VT]]: ... class _CacheInfo(NamedTuple): hits: int @@ -106,22 +106,35 @@ class _CacheInfo(NamedTuple): maxsize: int | None currsize: int +@type_check_only +class _AbstractCondition(AbstractContextManager[Any], Protocol): + # def wait(self, timeout: float | None = None) -> bool: ... + def wait_for(self, predicate: Callable[[], _T], timeout: float | None = None) -> _T: ... + # def notify(self, n: int = 1) -> None: ... + def notify_all(self) -> None: ... + @type_check_only class _cached_wrapper(Generic[_R]): __wrapped__: Callable[..., _R] + __name__: str + __doc__: str | None + cache: MutableMapping[Any, Any] | None + cache_key: Callable[..., Any] = ... + cache_lock: AbstractContextManager[Any] | None = None + cache_condition: _AbstractCondition | None = None def __call__(self, /, *args: Any, **kwargs: Any) -> _R: ... + def cache_clear(self) -> None: ... @type_check_only class _cached_wrapper_info(_cached_wrapper[_R]): def cache_info(self) -> _CacheInfo: ... - def cache_clear(self) -> None: ... @overload def cached( cache: MutableMapping[_KT, Any] | None, key: Callable[..., _KT] = ..., lock: AbstractContextManager[Any] | None = None, - condition: Condition | None = None, + condition: _AbstractCondition | None = None, info: Literal[True] = ..., ) -> Callable[[Callable[..., _R]], _cached_wrapper_info[_R]]: ... @overload @@ -129,28 +142,38 @@ def cached( cache: MutableMapping[_KT, Any] | None, key: Callable[..., _KT] = ..., lock: AbstractContextManager[Any] | None = None, - condition: Condition | None = None, + condition: _AbstractCondition | None = None, info: Literal[False] = ..., ) -> Callable[[Callable[..., _R]], _cached_wrapper[_R]]: ... +@type_check_only +class _cachedmethod_wrapper(Generic[_R]): + __wrapped__: Callable[..., _R] + __name__: str + __doc__: str | None + cache: MutableMapping[Any, Any] | None + cache_key: Callable[..., Any] = ... + cache_lock: AbstractContextManager[Any] | None = None + cache_condition: _AbstractCondition | None = None + def __call__(self, obj, /, *args: Any, **kwargs: Any) -> _R: ... + def cache_clear(self) -> None: ... + +@type_check_only +class _cachedmethod_wrapper_info(_cachedmethod_wrapper[_R]): + def cache_info(self) -> _CacheInfo: ... + @overload -@deprecated("Passing `info` as positional parameter is deprecated.") -def cached( - cache: MutableMapping[_KT, Any] | None, +def cachedmethod( + cache: Callable[[Any], MutableMapping[_KT, Any]], key: Callable[..., _KT] = ..., - lock: AbstractContextManager[Any] | None = None, - condition: Literal[True] = ..., -) -> Callable[[Callable[..., _R]], _cached_wrapper_info[_R]]: ... + lock: Callable[[Any], AbstractContextManager[Any]] | None = None, + condition: Callable[[Any], _AbstractCondition] | None = None, + info: Literal[True] = ..., +) -> Callable[[Callable[..., _R]], _cachedmethod_wrapper_info[_R]]: ... @overload -@deprecated("Passing `info` as positional parameter is deprecated.") -def cached( - cache: MutableMapping[_KT, Any] | None, - key: Callable[..., _KT] = ..., - lock: AbstractContextManager[Any] | None = None, - condition: Literal[False] | None = ..., -) -> Callable[[Callable[..., _R]], _cached_wrapper[_R]]: ... def cachedmethod( - cache: Callable[[Any], MutableMapping[_KT, Any] | None], + cache: Callable[[Any], MutableMapping[_KT, Any]], key: Callable[..., _KT] = ..., lock: Callable[[Any], AbstractContextManager[Any]] | None = None, - condition: Condition | None = None, -) -> IdentityFunction: ... + condition: Callable[[Any], _AbstractCondition] | None = None, + info: Literal[False] = ..., +) -> Callable[[Callable[..., _R]], _cachedmethod_wrapper[_R]]: ... diff --git a/stubs/cachetools/cachetools/keys.pyi b/stubs/cachetools/cachetools/keys.pyi index be1c7903c9c0..feccf6f9bcea 100644 --- a/stubs/cachetools/cachetools/keys.pyi +++ b/stubs/cachetools/cachetools/keys.pyi @@ -1,7 +1,8 @@ from _typeshed import Unused from collections.abc import Hashable +from typing import Final -__all__ = ("hashkey", "methodkey", "typedkey", "typedmethodkey") +__all__: Final = ("hashkey", "methodkey", "typedkey", "typedmethodkey") def hashkey(*args: Hashable, **kwargs: Hashable) -> tuple[Hashable, ...]: ... def methodkey(self: Unused, /, *args: Hashable, **kwargs: Hashable) -> tuple[Hashable, ...]: ... From eb4c33e42d4d85c3f955811a4caaf44a4f19974f Mon Sep 17 00:00:00 2001 From: Thomas Kemmer Date: Mon, 20 Apr 2026 10:30:31 +0200 Subject: [PATCH 2/3] [cachetools] Update to 7.0.* (#15357) --- stubs/cachetools/cachetools/__init__.pyi | 56 +++++------------------- 1 file changed, 12 insertions(+), 44 deletions(-) diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index 0e7114f689d5..646f9c64997c 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -1,5 +1,7 @@ from collections.abc import Callable, Iterator, MutableMapping, Sequence from contextlib import AbstractContextManager +import random +import time from typing import Any, Final, Generic, Literal, NamedTuple, Protocol, TypeVar, overload, type_check_only __all__: Final = ("Cache", "FIFOCache", "LFUCache", "LRUCache", "RRCache", "TLRUCache", "TTLCache", "cached", "cachedmethod") @@ -36,26 +38,12 @@ class LFUCache(Cache[_KT, _VT]): ... class LRUCache(Cache[_KT, _VT]): ... class RRCache(Cache[_KT, _VT]): - @overload - def __init__(self, maxsize: float, choice: None = None, getsizeof: None = None) -> None: ... - @overload - def __init__(self, maxsize: float, *, getsizeof: Callable[[_VT], float]) -> None: ... - @overload - def __init__(self, maxsize: float, choice: None, getsizeof: Callable[[_VT], float]) -> None: ... - @overload - def __init__(self, maxsize: float, choice: Callable[[Sequence[_KT]], _KT], getsizeof: None = None) -> None: ... - @overload - def __init__(self, maxsize: float, choice: Callable[[Sequence[_KT]], _KT], getsizeof: Callable[[_VT], float]) -> None: ... + def __init__(self, maxsize: float, choice: Callable[[Sequence[_KT]], _KT] = random.choice, getsizeof: Callable[[_VT], float] | None = None) -> None: ... @property def choice(self) -> Callable[[Sequence[_KT]], _KT]: ... -class _TimedCache(Cache[_KT, _VT]): - @overload - def __init__(self, maxsize: float, timer: Callable[[], _TT] = ..., getsizeof: None = None): ... - @overload - def __init__(self, maxsize: float, timer: Callable[[], _TT], getsizeof: Callable[[_VT], float]): ... - @overload - def __init__(self, maxsize: float, timer: Callable[[], _TT] = ..., *, getsizeof: Callable[[_VT], float]): ... +class _TimedCache[_KT, _VT, _TT](Cache[_KT, _VT]): + def __init__(self, maxsize: float, timer: Callable[..., _TT] = time.monotonic, getsizeof: Callable[[_VT], float] | None = None): ... class _Timer: def __init__(self, timer: Callable[[], _TT]) -> None: ... @@ -67,38 +55,18 @@ class _TimedCache(Cache[_KT, _VT]): @property def timer(self) -> _Timer: ... -class TTLCache(_TimedCache[_KT, _VT]): - @overload - def __init__(self, maxsize: float, ttl: Any, timer: Callable[..., _TT] = ..., getsizeof: None = None): ... - @overload - def __init__(self, maxsize: float, ttl: Any, timer: Callable[..., _TT], getsizeof: Callable[[_VT], float]): ... - @overload - def __init__(self, maxsize: float, ttl: Any, timer: Callable[..., _TT] = ..., *, getsizeof: Callable[[_VT], float]): ... +# FIXME: ttl should be "addable" to _TT +class TTLCache(_TimedCache[_KT, _VT, _TT]): + def __init__(self, maxsize: float, ttl: Any, timer: Callable[..., _TT] = time.monotonic, getsizeof: Callable[[_VT], float] | None = None): ... @property def ttl(self) -> Any: ... - def expire(self, time: Any | None = None) -> list[tuple[_KT, _VT]]: ... + def expire(self, time: _TT | None = None) -> list[tuple[_KT, _VT]]: ... -class TLRUCache(_TimedCache[_KT, _VT]): - @overload - def __init__( - self, maxsize: float, ttu: Callable[[_KT, _VT, _TT], _TT], timer: Callable[..., _TT] = ..., getsizeof: None = None - ): ... - @overload - def __init__( - self, maxsize: float, ttu: Callable[[_KT, _VT, _TT], _TT], timer: Callable[..., _TT], getsizeof: Callable[[_VT], float] - ): ... - @overload - def __init__( - self, - maxsize: float, - ttu: Callable[[_KT, _VT, _TT], _TT], - timer: Callable[..., _TT] = ..., - *, - getsizeof: Callable[[_VT], float], - ): ... +class TLRUCache(_TimedCache[_KT, _VT, _TT]): + def __init__(self, maxsize: float, ttu: Callable[[_KT, _VT, _TT], _TT], timer: Callable[..., _TT] = time.monotonic, getsizeof: Callable[[_VT], float] | None = None): ... @property def ttu(self) -> Callable[[_KT, _VT, _TT], _TT]: ... - def expire(self, time: Any | None = None) -> list[tuple[_KT, _VT]]: ... + def expire(self, time: _TT | None = None) -> list[tuple[_KT, _VT]]: ... class _CacheInfo(NamedTuple): hits: int From 23840d82b17b87df46e49b093f28427ee4bdc907 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 Apr 2026 08:34:37 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/cachetools/cachetools/__init__.pyi | 33 +++++++++++++++++++----- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index 646f9c64997c..bccbc0f6b21f 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -1,7 +1,7 @@ -from collections.abc import Callable, Iterator, MutableMapping, Sequence -from contextlib import AbstractContextManager import random import time +from collections.abc import Callable, Iterator, MutableMapping, Sequence +from contextlib import AbstractContextManager from typing import Any, Final, Generic, Literal, NamedTuple, Protocol, TypeVar, overload, type_check_only __all__: Final = ("Cache", "FIFOCache", "LFUCache", "LRUCache", "RRCache", "TLRUCache", "TTLCache", "cached", "cachedmethod") @@ -38,12 +38,19 @@ class LFUCache(Cache[_KT, _VT]): ... class LRUCache(Cache[_KT, _VT]): ... class RRCache(Cache[_KT, _VT]): - def __init__(self, maxsize: float, choice: Callable[[Sequence[_KT]], _KT] = random.choice, getsizeof: Callable[[_VT], float] | None = None) -> None: ... + def __init__( + self, + maxsize: float, + choice: Callable[[Sequence[_KT]], _KT] = random.choice, + getsizeof: Callable[[_VT], float] | None = None, + ) -> None: ... @property def choice(self) -> Callable[[Sequence[_KT]], _KT]: ... -class _TimedCache[_KT, _VT, _TT](Cache[_KT, _VT]): - def __init__(self, maxsize: float, timer: Callable[..., _TT] = time.monotonic, getsizeof: Callable[[_VT], float] | None = None): ... +class _TimedCache[KT, VT, TT](Cache[KT, VT]): + def __init__( + self, maxsize: float, timer: Callable[..., _TT] = time.monotonic, getsizeof: Callable[[_VT], float] | None = None + ): ... class _Timer: def __init__(self, timer: Callable[[], _TT]) -> None: ... @@ -57,13 +64,25 @@ class _TimedCache[_KT, _VT, _TT](Cache[_KT, _VT]): # FIXME: ttl should be "addable" to _TT class TTLCache(_TimedCache[_KT, _VT, _TT]): - def __init__(self, maxsize: float, ttl: Any, timer: Callable[..., _TT] = time.monotonic, getsizeof: Callable[[_VT], float] | None = None): ... + def __init__( + self, + maxsize: float, + ttl: Any, + timer: Callable[..., _TT] = time.monotonic, + getsizeof: Callable[[_VT], float] | None = None, + ): ... @property def ttl(self) -> Any: ... def expire(self, time: _TT | None = None) -> list[tuple[_KT, _VT]]: ... class TLRUCache(_TimedCache[_KT, _VT, _TT]): - def __init__(self, maxsize: float, ttu: Callable[[_KT, _VT, _TT], _TT], timer: Callable[..., _TT] = time.monotonic, getsizeof: Callable[[_VT], float] | None = None): ... + def __init__( + self, + maxsize: float, + ttu: Callable[[_KT, _VT, _TT], _TT], + timer: Callable[..., _TT] = time.monotonic, + getsizeof: Callable[[_VT], float] | None = None, + ): ... @property def ttu(self) -> Callable[[_KT, _VT, _TT], _TT]: ... def expire(self, time: _TT | None = None) -> list[tuple[_KT, _VT]]: ...