From e66b742f154d9f31752471e7966618c58c3dec77 Mon Sep 17 00:00:00 2001 From: Akuli Date: Tue, 8 Mar 2022 00:23:53 +0200 Subject: [PATCH 1/8] Update cachetools to 5.0.0 --- stubs/cachetools/METADATA.toml | 2 +- stubs/cachetools/cachetools/__init__.pyi | 34 +++++++++++++++++++++--- stubs/cachetools/cachetools/cache.pyi | 2 -- stubs/cachetools/cachetools/fifo.pyi | 2 -- stubs/cachetools/cachetools/func.pyi | 2 ++ 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 -- 11 files changed, 35 insertions(+), 19 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/METADATA.toml b/stubs/cachetools/METADATA.toml index cb7498d03056..c98db63045e7 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 06088cadd40a..d34b43e16ed1 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -7,6 +7,21 @@ _KT = TypeVar("_KT") _VT = TypeVar("_VT") _T = TypeVar("_T") +__all__ = ( + "Cache", + "FIFOCache", + "LFUCache", + "LRUCache", + "MRUCache", + "RRCache", + "TLRUCache", + "TTLCache", + "cached", + "cachedmethod", +) + +__version__: str + class Cache(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ... def __getitem__(self, key: _KT) -> _VT: ... @@ -45,18 +60,31 @@ 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, ttl: float, timer: Callable[[], float] = ..., getsizeof: Callable[[_VT], float] | None = ... + self, maxsize: float, timer: Callable[[], float] = ..., getsizeof: Callable[[_VT], float] | None = ... ) -> None: ... @property def currsize(self) -> float: ... @property - def timer(self) -> Callable[[], float]: ... + def timer(self) -> Callable[[], float]: ... # TODO: this is a callable but also a context manager + +class TTLCache(_TimedCache[_KT, _VT]): + def __init__( + self, maxsize: float, ttl: float, timer: Callable[[], float] = ..., getsizeof: Callable[[_VT], float] | None = ... + ) -> None: ... @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 a9bd3f70f626..000000000000 --- 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 c6b386ad455a..000000000000 --- 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 8135f8d140f3..00da54357a38 100644 --- a/stubs/cachetools/cachetools/func.pyi +++ b/stubs/cachetools/cachetools/func.pyi @@ -3,6 +3,8 @@ from typing import Callable, Sequence, TypeVar _T = TypeVar("_T") +__all__ = ("fifo_cache", "lfu_cache", "lru_cache", "mru_cache", "rr_cache", "ttl_cache") + def fifo_cache(maxsize: float | None = ..., typed: bool = ...) -> IdentityFunction: ... def lfu_cache(maxsize: float | None = ..., typed: bool = ...) -> IdentityFunction: ... def lru_cache(maxsize: float | None = ..., typed: bool = ...) -> IdentityFunction: ... diff --git a/stubs/cachetools/cachetools/keys.pyi b/stubs/cachetools/cachetools/keys.pyi index ef3e1120f4f9..7d810b0891fa 100644 --- a/stubs/cachetools/cachetools/keys.pyi +++ b/stubs/cachetools/cachetools/keys.pyi @@ -1,4 +1,4 @@ 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 9951e65e2841..000000000000 --- 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 4ea2d6413ca6..000000000000 --- 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 b345f5262b04..000000000000 --- 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 18e2098ceb66..000000000000 --- 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 aee05857648a..000000000000 --- a/stubs/cachetools/cachetools/ttl.pyi +++ /dev/null @@ -1,2 +0,0 @@ -# this module is deprecated -from . import TTLCache as TTLCache From 6cc651b1c99f893137d01423e0349c987a72c8ec Mon Sep 17 00:00:00 2001 From: Akuli Date: Tue, 8 Mar 2022 00:25:56 +0200 Subject: [PATCH 2/8] syntax error --- stubs/cachetools/cachetools/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index d34b43e16ed1..acdcbd147834 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -60,7 +60,7 @@ class RRCache(Cache[_KT, _VT]): @property def choice(self) -> Callable[[Sequence[_KT]], _KT]: ... -class _TimedCache(Cache[_KT, _VT]) +class _TimedCache(Cache[_KT, _VT]): def __init__( self, maxsize: float, timer: Callable[[], float] = ..., getsizeof: Callable[[_VT], float] | None = ... ) -> None: ... From 8dca588ece136c3e76c68af864b6fbd1b702bceb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Mar 2022 22:26:33 +0000 Subject: [PATCH 3/8] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/cachetools/cachetools/__init__.pyi | 19 ++++++------------- stubs/cachetools/cachetools/keys.pyi | 2 ++ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index acdcbd147834..0ac90f366243 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -7,18 +7,7 @@ _KT = TypeVar("_KT") _VT = TypeVar("_VT") _T = TypeVar("_T") -__all__ = ( - "Cache", - "FIFOCache", - "LFUCache", - "LRUCache", - "MRUCache", - "RRCache", - "TLRUCache", - "TTLCache", - "cached", - "cachedmethod", -) +__all__ = ("Cache", "FIFOCache", "LFUCache", "LRUCache", "MRUCache", "RRCache", "TLRUCache", "TTLCache", "cached", "cachedmethod") __version__: str @@ -79,7 +68,11 @@ class TTLCache(_TimedCache[_KT, _VT]): class TLRUCache(_TimedCache[_KT, _VT]): def __init__( - self, maxsize: float, ttu: Callable[[_KT, _VT, float], float], timer: Callable[[], float] = ..., getsizeof: Callable[[_VT], float] | None = ... + 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]: ... diff --git a/stubs/cachetools/cachetools/keys.pyi b/stubs/cachetools/cachetools/keys.pyi index 7d810b0891fa..c1867dce6910 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, ...]: ... From 68d8d7baf3e910ffed583ad5285684c089082616 Mon Sep 17 00:00:00 2001 From: Akuli Date: Tue, 8 Mar 2022 00:40:42 +0200 Subject: [PATCH 4/8] stubtest fixes --- .../cachetools/@tests/stubtest_allowlist.txt | 25 +++++++++++++++---- stubs/cachetools/cachetools/__init__.pyi | 1 + 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/stubs/cachetools/@tests/stubtest_allowlist.txt b/stubs/cachetools/@tests/stubtest_allowlist.txt index f4aafb87c685..077ad455374d 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/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index acdcbd147834..79552314a880 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -27,6 +27,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] From 5ae63cc9ca03d2e9ec90e6d269ece04a7c855bd4 Mon Sep 17 00:00:00 2001 From: Akuli Date: Tue, 8 Mar 2022 00:41:42 +0200 Subject: [PATCH 5/8] tiny rearranging --- stubs/cachetools/cachetools/__init__.pyi | 7 +++---- stubs/cachetools/cachetools/func.pyi | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index 3e1d25f87ee7..9ad43f0bda9c 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -3,14 +3,13 @@ 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") -__all__ = ("Cache", "FIFOCache", "LFUCache", "LRUCache", "MRUCache", "RRCache", "TLRUCache", "TTLCache", "cached", "cachedmethod") - -__version__: str - class Cache(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ... def __getitem__(self, key: _KT) -> _VT: ... diff --git a/stubs/cachetools/cachetools/func.pyi b/stubs/cachetools/cachetools/func.pyi index 00da54357a38..378cbd91d065 100644 --- a/stubs/cachetools/cachetools/func.pyi +++ b/stubs/cachetools/cachetools/func.pyi @@ -1,9 +1,8 @@ from _typeshed import IdentityFunction from typing import Callable, Sequence, TypeVar -_T = TypeVar("_T") - __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: ... def lfu_cache(maxsize: float | None = ..., typed: bool = ...) -> IdentityFunction: ... From 1d6a9ee6466c41ef6a740e9fd350e94015a808ed Mon Sep 17 00:00:00 2001 From: Akuli Date: Tue, 8 Mar 2022 21:08:35 +0200 Subject: [PATCH 6/8] return _Timer --- stubs/cachetools/cachetools/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index 9ad43f0bda9c..4909daed2229 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -56,7 +56,7 @@ class _TimedCache(Cache[_KT, _VT]): @property def currsize(self) -> float: ... @property - def timer(self) -> Callable[[], float]: ... # TODO: this is a callable but also a context manager + def timer(self) -> _Timer: ... class TTLCache(_TimedCache[_KT, _VT]): def __init__( From 5eff2d0e53daaad464e259afb051775538554109 Mon Sep 17 00:00:00 2001 From: Akuli Date: Tue, 8 Mar 2022 21:07:05 +0200 Subject: [PATCH 7/8] Update stubs/cachetools/cachetools/__init__.pyi Co-authored-by: Alex Waygood --- stubs/cachetools/cachetools/__init__.pyi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index 4909daed2229..964248f6cc2b 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -55,6 +55,11 @@ class _TimedCache(Cache[_KT, _VT]): ) -> 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: ... From 1f6b48aa642cc32d5d653a21e591abb43a44076c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 8 Mar 2022 19:09:23 +0000 Subject: [PATCH 8/8] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/cachetools/cachetools/__init__.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index 964248f6cc2b..e4accb322c1d 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -55,11 +55,13 @@ class _TimedCache(Cache[_KT, _VT]): ) -> 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: ...