From 6c967d4202bb3bca716ded414f3c4ebd56f4cd21 Mon Sep 17 00:00:00 2001 From: Akuli Date: Tue, 8 Mar 2022 21:20:22 +0200 Subject: [PATCH] Update cachetools to 5.0.0 (#7455) Co-authored-by: Alex Waygood Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .../cachetools/@tests/stubtest_allowlist.txt | 25 +++++++++--- stubs/cachetools/METADATA.toml | 2 +- stubs/cachetools/cachetools/__init__.pyi | 38 ++++++++++++++++--- stubs/cachetools/cachetools/cache.pyi | 2 - stubs/cachetools/cachetools/fifo.pyi | 2 - stubs/cachetools/cachetools/func.pyi | 1 + stubs/cachetools/cachetools/keys.pyi | 2 + stubs/cachetools/cachetools/lfu.pyi | 2 - stubs/cachetools/cachetools/lru.pyi | 2 - stubs/cachetools/cachetools/mru.pyi | 2 - stubs/cachetools/cachetools/rr.pyi | 2 - stubs/cachetools/cachetools/ttl.pyi | 2 - 12 files changed, 57 insertions(+), 25 deletions(-) delete mode 100644 stubs/cachetools/cachetools/cache.pyi delete mode 100644 stubs/cachetools/cachetools/fifo.pyi delete mode 100644 stubs/cachetools/cachetools/lfu.pyi delete mode 100644 stubs/cachetools/cachetools/lru.pyi delete mode 100644 stubs/cachetools/cachetools/mru.pyi delete mode 100644 stubs/cachetools/cachetools/rr.pyi delete mode 100644 stubs/cachetools/cachetools/ttl.pyi diff --git a/stubs/cachetools/@tests/stubtest_allowlist.txt b/stubs/cachetools/@tests/stubtest_allowlist.txt index f4aafb87c..077ad4553 100644 --- a/stubs/cachetools/@tests/stubtest_allowlist.txt +++ b/stubs/cachetools/@tests/stubtest_allowlist.txt @@ -1,7 +1,22 @@ cachetools.Cache.get -cachetools.cache.Cache.get -# it looks like cachetools stubs are really out of date, so none of the modules -# referenced exist anymore -cachetools\..*\.__(get|set|del)item__ # has extra argument -cachetools\..*TTLCache.__repr__ +# stubs omit defaulted arguments that are meant to be optimizations, not provided by user +cachetools.FIFOCache.__delitem__ +cachetools.FIFOCache.__setitem__ +cachetools.LFUCache.__delitem__ +cachetools.LFUCache.__getitem__ +cachetools.LFUCache.__setitem__ +cachetools.LRUCache.__delitem__ +cachetools.LRUCache.__getitem__ +cachetools.LRUCache.__setitem__ +cachetools.MRUCache.__delitem__ +cachetools.MRUCache.__getitem__ +cachetools.MRUCache.__setitem__ +cachetools.TLRUCache.__delitem__ +cachetools.TLRUCache.__getitem__ +cachetools.TLRUCache.__setitem__ +cachetools.TTLCache.__delitem__ +cachetools.TTLCache.__getitem__ +cachetools.TTLCache.__setitem__ +cachetools._TimedCache.__len__ +cachetools._TimedCache.__repr__ diff --git a/stubs/cachetools/METADATA.toml b/stubs/cachetools/METADATA.toml index cb7498d03..c98db6304 100644 --- a/stubs/cachetools/METADATA.toml +++ b/stubs/cachetools/METADATA.toml @@ -1 +1 @@ -version = "4.2.*" +version = "5.0.*" diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index 06088cadd..e4accb322 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -3,6 +3,9 @@ from collections.abc import Iterator, Sequence from contextlib import AbstractContextManager from typing import Any, Callable, Generic, MutableMapping, TypeVar, overload +__all__ = ("Cache", "FIFOCache", "LFUCache", "LRUCache", "MRUCache", "RRCache", "TLRUCache", "TTLCache", "cached", "cachedmethod") +__version__: str + _KT = TypeVar("_KT") _VT = TypeVar("_VT") _T = TypeVar("_T") @@ -12,6 +15,7 @@ class Cache(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __getitem__(self, key: _KT) -> _VT: ... def __setitem__(self, key: _KT, value: _VT) -> None: ... def __delitem__(self, key: _KT) -> None: ... + def __missing__(self, key: _KT) -> _VT: ... def __iter__(self) -> Iterator[_KT]: ... def __len__(self) -> int: ... @overload # type: ignore[override] @@ -45,18 +49,42 @@ class RRCache(Cache[_KT, _VT]): @property def choice(self) -> Callable[[Sequence[_KT]], _KT]: ... -class TTLCache(Cache[_KT, _VT]): +class _TimedCache(Cache[_KT, _VT]): + def __init__( + self, maxsize: float, timer: Callable[[], float] = ..., getsizeof: Callable[[_VT], float] | None = ... + ) -> None: ... + @property + def currsize(self) -> float: ... + + class _Timer: + def __init__(self, timer: Callable[[], float]) -> None: ... + def __call__(self) -> float: ... + def __enter__(self) -> float: ... + def __exit__(self, *exc: object) -> None: ... + + @property + def timer(self) -> _Timer: ... + +class TTLCache(_TimedCache[_KT, _VT]): def __init__( self, maxsize: float, ttl: float, timer: Callable[[], float] = ..., getsizeof: Callable[[_VT], float] | None = ... ) -> None: ... @property - def currsize(self) -> float: ... - @property - def timer(self) -> Callable[[], float]: ... - @property def ttl(self) -> float: ... def expire(self, time: float | None = ...) -> None: ... +class TLRUCache(_TimedCache[_KT, _VT]): + def __init__( + self, + maxsize: float, + ttu: Callable[[_KT, _VT, float], float], + timer: Callable[[], float] = ..., + getsizeof: Callable[[_VT], float] | None = ..., + ) -> None: ... + @property + def ttu(self) -> Callable[[_KT, _VT, float], float]: ... + def expire(self, time: float | None = ...) -> None: ... + def cached( cache: MutableMapping[_KT, Any] | None, key: Callable[..., _KT] = ..., lock: AbstractContextManager[Any] | None = ... ) -> IdentityFunction: ... diff --git a/stubs/cachetools/cachetools/cache.pyi b/stubs/cachetools/cachetools/cache.pyi deleted file mode 100644 index a9bd3f70f..000000000 --- a/stubs/cachetools/cachetools/cache.pyi +++ /dev/null @@ -1,2 +0,0 @@ -# this module is deprecated -from . import Cache as Cache diff --git a/stubs/cachetools/cachetools/fifo.pyi b/stubs/cachetools/cachetools/fifo.pyi deleted file mode 100644 index c6b386ad4..000000000 --- a/stubs/cachetools/cachetools/fifo.pyi +++ /dev/null @@ -1,2 +0,0 @@ -# this module is deprecated -from . import FIFOCache as FIFOCache diff --git a/stubs/cachetools/cachetools/func.pyi b/stubs/cachetools/cachetools/func.pyi index 8135f8d14..378cbd91d 100644 --- a/stubs/cachetools/cachetools/func.pyi +++ b/stubs/cachetools/cachetools/func.pyi @@ -1,6 +1,7 @@ from _typeshed import IdentityFunction from typing import Callable, Sequence, TypeVar +__all__ = ("fifo_cache", "lfu_cache", "lru_cache", "mru_cache", "rr_cache", "ttl_cache") _T = TypeVar("_T") def fifo_cache(maxsize: float | None = ..., typed: bool = ...) -> IdentityFunction: ... diff --git a/stubs/cachetools/cachetools/keys.pyi b/stubs/cachetools/cachetools/keys.pyi index ef3e1120f..c1867dce6 100644 --- a/stubs/cachetools/cachetools/keys.pyi +++ b/stubs/cachetools/cachetools/keys.pyi @@ -1,4 +1,6 @@ from typing import Hashable +__all__ = ("hashkey", "typedkey") + def hashkey(*args: Hashable, **kwargs: Hashable) -> tuple[Hashable, ...]: ... def typedkey(*args: Hashable, **kwargs: Hashable) -> tuple[Hashable, ...]: ... diff --git a/stubs/cachetools/cachetools/lfu.pyi b/stubs/cachetools/cachetools/lfu.pyi deleted file mode 100644 index 9951e65e2..000000000 --- a/stubs/cachetools/cachetools/lfu.pyi +++ /dev/null @@ -1,2 +0,0 @@ -# this module is deprecated -from . import LFUCache as LFUCache diff --git a/stubs/cachetools/cachetools/lru.pyi b/stubs/cachetools/cachetools/lru.pyi deleted file mode 100644 index 4ea2d6413..000000000 --- a/stubs/cachetools/cachetools/lru.pyi +++ /dev/null @@ -1,2 +0,0 @@ -# this module is deprecated -from . import LRUCache as LRUCache diff --git a/stubs/cachetools/cachetools/mru.pyi b/stubs/cachetools/cachetools/mru.pyi deleted file mode 100644 index b345f5262..000000000 --- a/stubs/cachetools/cachetools/mru.pyi +++ /dev/null @@ -1,2 +0,0 @@ -# this module is deprecated -from . import MRUCache as MRUCache diff --git a/stubs/cachetools/cachetools/rr.pyi b/stubs/cachetools/cachetools/rr.pyi deleted file mode 100644 index 18e2098ce..000000000 --- a/stubs/cachetools/cachetools/rr.pyi +++ /dev/null @@ -1,2 +0,0 @@ -# this module is deprecated -from . import RRCache as RRCache diff --git a/stubs/cachetools/cachetools/ttl.pyi b/stubs/cachetools/cachetools/ttl.pyi deleted file mode 100644 index aee058576..000000000 --- a/stubs/cachetools/cachetools/ttl.pyi +++ /dev/null @@ -1,2 +0,0 @@ -# this module is deprecated -from . import TTLCache as TTLCache