From eb551bd2bf70eeb479d05f0cf4fb7009b47f1541 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 30 Sep 2021 16:11:31 +0300 Subject: [PATCH 01/12] Revert "Unbreak CI (#6093)" This reverts commit 32bc2161a107db20c2ebc85aad31c29730db3e38. --- .../cachetools/@tests/stubtest_allowlist.txt | 26 +++++++++++++++++++ stubs/cachetools/METADATA.toml | 1 + stubs/cachetools/cachetools/__init__.pyi | 6 +++++ stubs/cachetools/cachetools/abc.pyi | 7 +++++ stubs/cachetools/cachetools/cache.pyi | 20 ++++++++++++++ stubs/cachetools/cachetools/decorators.pyi | 11 ++++++++ stubs/cachetools/cachetools/func.pyi | 9 +++++++ stubs/cachetools/cachetools/keys.pyi | 4 +++ stubs/cachetools/cachetools/lfu.pyi | 14 ++++++++++ stubs/cachetools/cachetools/lru.pyi | 13 ++++++++++ stubs/cachetools/cachetools/rr.pyi | 18 +++++++++++++ stubs/cachetools/cachetools/ttl.pyi | 23 ++++++++++++++++ 12 files changed, 152 insertions(+) create mode 100644 stubs/cachetools/@tests/stubtest_allowlist.txt create mode 100644 stubs/cachetools/METADATA.toml create mode 100644 stubs/cachetools/cachetools/__init__.pyi create mode 100644 stubs/cachetools/cachetools/abc.pyi create mode 100644 stubs/cachetools/cachetools/cache.pyi create mode 100644 stubs/cachetools/cachetools/decorators.pyi create mode 100644 stubs/cachetools/cachetools/func.pyi create mode 100644 stubs/cachetools/cachetools/keys.pyi create mode 100644 stubs/cachetools/cachetools/lfu.pyi create mode 100644 stubs/cachetools/cachetools/lru.pyi create mode 100644 stubs/cachetools/cachetools/rr.pyi create mode 100644 stubs/cachetools/cachetools/ttl.pyi diff --git a/stubs/cachetools/@tests/stubtest_allowlist.txt b/stubs/cachetools/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000000..b041adaf5ce4 --- /dev/null +++ b/stubs/cachetools/@tests/stubtest_allowlist.txt @@ -0,0 +1,26 @@ +cachetools.Cache.get +cachetools.LFUCache.__delitem__ +cachetools.LFUCache.__getitem__ +cachetools.LFUCache.__setitem__ +cachetools.LRUCache.__delitem__ +cachetools.LRUCache.__getitem__ +cachetools.LRUCache.__setitem__ +cachetools.TTLCache.__delitem__ +cachetools.TTLCache.__getitem__ +cachetools.TTLCache.__setitem__ +cachetools.abc +cachetools.cache.Cache.get +cachetools.cache.DefaultMapping +cachetools.func.ttl_cache +cachetools.lfu.LFUCache.__delitem__ +cachetools.lfu.LFUCache.__getitem__ +cachetools.lfu.LFUCache.__setitem__ +cachetools.lru.Cache.get +cachetools.lru.LRUCache.__delitem__ +cachetools.lru.LRUCache.__getitem__ +cachetools.lru.LRUCache.__setitem__ +cachetools.rr.Cache.get +cachetools.ttl.Cache.get +cachetools.ttl.TTLCache.__delitem__ +cachetools.ttl.TTLCache.__getitem__ +cachetools.ttl.TTLCache.__setitem__ diff --git a/stubs/cachetools/METADATA.toml b/stubs/cachetools/METADATA.toml new file mode 100644 index 000000000000..de720977e07a --- /dev/null +++ b/stubs/cachetools/METADATA.toml @@ -0,0 +1 @@ +version = "4.2" diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi new file mode 100644 index 000000000000..c6a9eaa95bc3 --- /dev/null +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -0,0 +1,6 @@ +from .cache import Cache as Cache +from .decorators import cached as cached, cachedmethod as cachedmethod +from .lfu import LFUCache as LFUCache +from .lru import LRUCache as LRUCache +from .rr import RRCache as RRCache +from .ttl import TTLCache as TTLCache diff --git a/stubs/cachetools/cachetools/abc.pyi b/stubs/cachetools/cachetools/abc.pyi new file mode 100644 index 000000000000..a1f0fbbdb7e6 --- /dev/null +++ b/stubs/cachetools/cachetools/abc.pyi @@ -0,0 +1,7 @@ +from abc import ABCMeta +from typing import MutableMapping, TypeVar + +_KT = TypeVar("_KT") +_VT = TypeVar("_VT") + +class DefaultMapping(MutableMapping[_KT, _VT], metaclass=ABCMeta): ... diff --git a/stubs/cachetools/cachetools/cache.pyi b/stubs/cachetools/cachetools/cache.pyi new file mode 100644 index 000000000000..ad5ff1473ff7 --- /dev/null +++ b/stubs/cachetools/cachetools/cache.pyi @@ -0,0 +1,20 @@ +from typing import Callable, Generic, Iterator, TypeVar + +from .abc import DefaultMapping as DefaultMapping + +_KT = TypeVar("_KT") +_VT = TypeVar("_VT") + +class Cache(DefaultMapping[_KT, _VT], Generic[_KT, _VT]): + 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: ... + def __iter__(self) -> Iterator[_KT]: ... + def __len__(self) -> int: ... + @property + def maxsize(self) -> float: ... + @property + def currsize(self) -> float: ... + @staticmethod + def getsizeof(value: _VT) -> float: ... diff --git a/stubs/cachetools/cachetools/decorators.pyi b/stubs/cachetools/cachetools/decorators.pyi new file mode 100644 index 000000000000..426fc871d665 --- /dev/null +++ b/stubs/cachetools/cachetools/decorators.pyi @@ -0,0 +1,11 @@ +from _typeshed import IdentityFunction +from typing import Any, Callable, ContextManager, MutableMapping, TypeVar + +_KT = TypeVar("_KT") + +def cached( + cache: MutableMapping[_KT, Any] | None, key: Callable[..., _KT] = ..., lock: ContextManager[Any] | None = ... +) -> IdentityFunction: ... +def cachedmethod( + cache: Callable[[Any], MutableMapping[_KT, Any] | None], key: Callable[..., _KT] = ..., lock: ContextManager[Any] | None = ... +) -> IdentityFunction: ... diff --git a/stubs/cachetools/cachetools/func.pyi b/stubs/cachetools/cachetools/func.pyi new file mode 100644 index 000000000000..75a532a00ba8 --- /dev/null +++ b/stubs/cachetools/cachetools/func.pyi @@ -0,0 +1,9 @@ +from _typeshed import IdentityFunction +from typing import Callable, Sequence, TypeVar + +_T = TypeVar("_T") + +def lfu_cache(maxsize: float = ..., typed: bool = ...) -> IdentityFunction: ... +def lru_cache(maxsize: float = ..., typed: bool = ...) -> IdentityFunction: ... +def rr_cache(maxsize: float = ..., choice: Callable[[Sequence[_T]], _T] | None = ..., typed: bool = ...) -> IdentityFunction: ... +def ttl_cache(maxsize: float = ..., ttl: float = ..., timer: float = ..., typed: bool = ...) -> IdentityFunction: ... diff --git a/stubs/cachetools/cachetools/keys.pyi b/stubs/cachetools/cachetools/keys.pyi new file mode 100644 index 000000000000..9effbe6e171f --- /dev/null +++ b/stubs/cachetools/cachetools/keys.pyi @@ -0,0 +1,4 @@ +from typing import Hashable, Tuple + +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 new file mode 100644 index 000000000000..e63aeb313628 --- /dev/null +++ b/stubs/cachetools/cachetools/lfu.pyi @@ -0,0 +1,14 @@ +from typing import Callable, Iterator, TypeVar + +from .cache import Cache + +_KT = TypeVar("_KT") +_VT = TypeVar("_VT") + +class LFUCache(Cache[_KT, _VT]): + def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ... + def __getitem__(self, key: _KT, cache_getitem: Callable[[_KT], _VT] = ...) -> _VT: ... + def __setitem__(self, key: _KT, value: _VT, cache_setitem: Callable[[_KT, _VT], None] = ...) -> None: ... + def __delitem__(self, key: _KT, cache_delitem: Callable[[_KT], None] = ...) -> None: ... + def __iter__(self) -> Iterator[_KT]: ... + def __len__(self) -> int: ... diff --git a/stubs/cachetools/cachetools/lru.pyi b/stubs/cachetools/cachetools/lru.pyi new file mode 100644 index 000000000000..128a91480aff --- /dev/null +++ b/stubs/cachetools/cachetools/lru.pyi @@ -0,0 +1,13 @@ +from typing import Callable, Iterator, TypeVar + +from .cache import Cache as Cache + +_KT = TypeVar("_KT") +_VT = TypeVar("_VT") + +class LRUCache(Cache[_KT, _VT]): + def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ... + def __getitem__(self, key: _KT, cache_getitem: Callable[[_KT], _VT] = ...) -> _VT: ... + def __setitem__(self, key: _KT, value: _VT, cache_setitem: Callable[[_KT, _VT], None] = ...) -> None: ... + def __delitem__(self, key: _KT, cache_delitem: Callable[[_KT], None] = ...) -> None: ... + def __iter__(self) -> Iterator[_KT]: ... diff --git a/stubs/cachetools/cachetools/rr.pyi b/stubs/cachetools/cachetools/rr.pyi new file mode 100644 index 000000000000..aa4190d047c2 --- /dev/null +++ b/stubs/cachetools/cachetools/rr.pyi @@ -0,0 +1,18 @@ +from typing import Callable, Iterator, Sequence, TypeVar + +from .cache import Cache as Cache + +_KT = TypeVar("_KT") +_VT = TypeVar("_VT") + +class RRCache(Cache[_KT, _VT]): + def __init__( + self, maxsize: float, choice: Callable[[Sequence[_KT]], _KT] | None = ..., 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: ... + def __iter__(self) -> Iterator[_KT]: ... + def __len__(self) -> int: ... + @property + def choice(self) -> Callable[[Sequence[_KT]], _KT]: ... diff --git a/stubs/cachetools/cachetools/ttl.pyi b/stubs/cachetools/cachetools/ttl.pyi new file mode 100644 index 000000000000..12cd6072cdfb --- /dev/null +++ b/stubs/cachetools/cachetools/ttl.pyi @@ -0,0 +1,23 @@ +from typing import Callable, Iterator, TypeVar + +from .cache import Cache as Cache + +_KT = TypeVar("_KT") +_VT = TypeVar("_VT") + +class TTLCache(Cache[_KT, _VT]): + def __init__( + self, maxsize: float, ttl: float, timer: Callable[[], float] = ..., getsizeof: Callable[[_VT], float] | None = ... + ) -> None: ... + def __getitem__(self, key: _KT, cache_getitem: Callable[[_KT], _VT] = ...) -> _VT: ... + def __setitem__(self, key: _KT, value: _VT, cache_setitem: Callable[[_KT, _VT], None] = ...) -> None: ... + def __delitem__(self, key: _KT, cache_delitem: Callable[[_KT], None] = ...) -> None: ... + def __iter__(self) -> Iterator[_KT]: ... + def __len__(self) -> int: ... + @property + def currsize(self) -> float: ... + @property + def timer(self) -> Callable[[], float]: ... + @property + def ttl(self) -> float: ... + def expire(self, time: float | None = ...) -> None: ... From 28a7c076a7abc183462fe53e0715b59b2b5c21b0 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 30 Sep 2021 16:14:21 +0300 Subject: [PATCH 02/12] delete abc.pyi --- stubs/cachetools/cachetools/abc.pyi | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 stubs/cachetools/cachetools/abc.pyi diff --git a/stubs/cachetools/cachetools/abc.pyi b/stubs/cachetools/cachetools/abc.pyi deleted file mode 100644 index a1f0fbbdb7e6..000000000000 --- a/stubs/cachetools/cachetools/abc.pyi +++ /dev/null @@ -1,7 +0,0 @@ -from abc import ABCMeta -from typing import MutableMapping, TypeVar - -_KT = TypeVar("_KT") -_VT = TypeVar("_VT") - -class DefaultMapping(MutableMapping[_KT, _VT], metaclass=ABCMeta): ... From 1f0f59849d5bf54ebbdf5ac8141460ace39b15ea Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 30 Sep 2021 16:15:00 +0300 Subject: [PATCH 03/12] move Cache to __init__.pyi --- stubs/cachetools/cachetools/__init__.pyi | 20 +++++++++++++++++++- stubs/cachetools/cachetools/cache.pyi | 22 ++-------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index c6a9eaa95bc3..a5f36da44711 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -1,6 +1,24 @@ -from .cache import Cache as Cache from .decorators import cached as cached, cachedmethod as cachedmethod from .lfu import LFUCache as LFUCache from .lru import LRUCache as LRUCache from .rr import RRCache as RRCache from .ttl import TTLCache as TTLCache + +from typing import Callable, Generic, Iterator, TypeVar + +_KT = TypeVar("_KT") +_VT = TypeVar("_VT") + +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: ... + def __setitem__(self, key: _KT, value: _VT) -> None: ... + def __delitem__(self, key: _KT) -> None: ... + def __iter__(self) -> Iterator[_KT]: ... + def __len__(self) -> int: ... + @property + def maxsize(self) -> float: ... + @property + def currsize(self) -> float: ... + @staticmethod + def getsizeof(value: _VT) -> float: ... diff --git a/stubs/cachetools/cachetools/cache.pyi b/stubs/cachetools/cachetools/cache.pyi index ad5ff1473ff7..a9bd3f70f626 100644 --- a/stubs/cachetools/cachetools/cache.pyi +++ b/stubs/cachetools/cachetools/cache.pyi @@ -1,20 +1,2 @@ -from typing import Callable, Generic, Iterator, TypeVar - -from .abc import DefaultMapping as DefaultMapping - -_KT = TypeVar("_KT") -_VT = TypeVar("_VT") - -class Cache(DefaultMapping[_KT, _VT], Generic[_KT, _VT]): - 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: ... - def __iter__(self) -> Iterator[_KT]: ... - def __len__(self) -> int: ... - @property - def maxsize(self) -> float: ... - @property - def currsize(self) -> float: ... - @staticmethod - def getsizeof(value: _VT) -> float: ... +# this module is deprecated +from . import Cache as Cache From 8850dbe03ac88126b714d632014d9b8f163114c9 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 30 Sep 2021 16:15:41 +0300 Subject: [PATCH 04/12] delete decorators.pyi --- stubs/cachetools/cachetools/__init__.pyi | 12 ++++++++++++ stubs/cachetools/cachetools/decorators.pyi | 11 ----------- 2 files changed, 12 insertions(+), 11 deletions(-) delete mode 100644 stubs/cachetools/cachetools/decorators.pyi diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index a5f36da44711..2d85217063df 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -6,6 +6,18 @@ from .ttl import TTLCache as TTLCache from typing import Callable, Generic, Iterator, TypeVar +from _typeshed import IdentityFunction +from typing import Any, Callable, ContextManager, MutableMapping, TypeVar + +_KT = TypeVar("_KT") + +def cached( + cache: MutableMapping[_KT, Any] | None, key: Callable[..., _KT] = ..., lock: ContextManager[Any] | None = ... +) -> IdentityFunction: ... +def cachedmethod( + cache: Callable[[Any], MutableMapping[_KT, Any] | None], key: Callable[..., _KT] = ..., lock: ContextManager[Any] | None = ... +) -> IdentityFunction: ... + _KT = TypeVar("_KT") _VT = TypeVar("_VT") diff --git a/stubs/cachetools/cachetools/decorators.pyi b/stubs/cachetools/cachetools/decorators.pyi deleted file mode 100644 index 426fc871d665..000000000000 --- a/stubs/cachetools/cachetools/decorators.pyi +++ /dev/null @@ -1,11 +0,0 @@ -from _typeshed import IdentityFunction -from typing import Any, Callable, ContextManager, MutableMapping, TypeVar - -_KT = TypeVar("_KT") - -def cached( - cache: MutableMapping[_KT, Any] | None, key: Callable[..., _KT] = ..., lock: ContextManager[Any] | None = ... -) -> IdentityFunction: ... -def cachedmethod( - cache: Callable[[Any], MutableMapping[_KT, Any] | None], key: Callable[..., _KT] = ..., lock: ContextManager[Any] | None = ... -) -> IdentityFunction: ... From a5150bd80d2e116eaed9c4969e4e129c9b202036 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 30 Sep 2021 16:17:05 +0300 Subject: [PATCH 05/12] add cachetools.func.fifo_cache and cachetools.func.mru_cache --- stubs/cachetools/cachetools/func.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stubs/cachetools/cachetools/func.pyi b/stubs/cachetools/cachetools/func.pyi index 75a532a00ba8..1ae2d8f3b1eb 100644 --- a/stubs/cachetools/cachetools/func.pyi +++ b/stubs/cachetools/cachetools/func.pyi @@ -3,7 +3,9 @@ from typing import Callable, Sequence, TypeVar _T = TypeVar("_T") +def fifo_cache(maxsize: float = ..., typed: bool = ...) -> IdentityFunction: ... def lfu_cache(maxsize: float = ..., typed: bool = ...) -> IdentityFunction: ... def lru_cache(maxsize: float = ..., typed: bool = ...) -> IdentityFunction: ... +def mru_cache(maxsize: float = ..., typed: bool = ...) -> IdentityFunction: ... def rr_cache(maxsize: float = ..., choice: Callable[[Sequence[_T]], _T] | None = ..., typed: bool = ...) -> IdentityFunction: ... def ttl_cache(maxsize: float = ..., ttl: float = ..., timer: float = ..., typed: bool = ...) -> IdentityFunction: ... From ea27f4443ddf6fa076229175ad58d23759812980 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 30 Sep 2021 16:30:28 +0300 Subject: [PATCH 06/12] move all the things to where they belong --- stubs/cachetools/cachetools/__init__.pyi | 67 ++++++++++++++++++++---- stubs/cachetools/cachetools/fifo.pyi | 2 + stubs/cachetools/cachetools/lfu.pyi | 16 +----- stubs/cachetools/cachetools/lru.pyi | 15 +----- stubs/cachetools/cachetools/mru.pyi | 2 + stubs/cachetools/cachetools/rr.pyi | 20 +------ 6 files changed, 68 insertions(+), 54 deletions(-) create mode 100644 stubs/cachetools/cachetools/fifo.pyi create mode 100644 stubs/cachetools/cachetools/mru.pyi diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index 2d85217063df..3adad0320481 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -9,15 +9,6 @@ from typing import Callable, Generic, Iterator, TypeVar from _typeshed import IdentityFunction from typing import Any, Callable, ContextManager, MutableMapping, TypeVar -_KT = TypeVar("_KT") - -def cached( - cache: MutableMapping[_KT, Any] | None, key: Callable[..., _KT] = ..., lock: ContextManager[Any] | None = ... -) -> IdentityFunction: ... -def cachedmethod( - cache: Callable[[Any], MutableMapping[_KT, Any] | None], key: Callable[..., _KT] = ..., lock: ContextManager[Any] | None = ... -) -> IdentityFunction: ... - _KT = TypeVar("_KT") _VT = TypeVar("_VT") @@ -34,3 +25,61 @@ class Cache(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def currsize(self) -> float: ... @staticmethod def getsizeof(value: _VT) -> float: ... + +class FIFOCache(Cache[_KT, _VT]): + pass # TODO + +class LFUCache(Cache[_KT, _VT]): + def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ... + def __getitem__(self, key: _KT, cache_getitem: Callable[[_KT], _VT] = ...) -> _VT: ... + def __setitem__(self, key: _KT, value: _VT, cache_setitem: Callable[[_KT, _VT], None] = ...) -> None: ... + def __delitem__(self, key: _KT, cache_delitem: Callable[[_KT], None] = ...) -> None: ... + def __iter__(self) -> Iterator[_KT]: ... + def __len__(self) -> int: ... + +class LRUCache(Cache[_KT, _VT]): + def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ... + def __getitem__(self, key: _KT, cache_getitem: Callable[[_KT], _VT] = ...) -> _VT: ... + def __setitem__(self, key: _KT, value: _VT, cache_setitem: Callable[[_KT, _VT], None] = ...) -> None: ... + def __delitem__(self, key: _KT, cache_delitem: Callable[[_KT], None] = ...) -> None: ... + def __iter__(self) -> Iterator[_KT]: ... + +class MRUCache(Cache[_KT, _VT]): + pass # TODO + +class RRCache(Cache[_KT, _VT]): + def __init__( + self, maxsize: float, choice: Callable[[Sequence[_KT]], _KT] | None = ..., 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: ... + def __iter__(self) -> Iterator[_KT]: ... + def __len__(self) -> int: ... + @property + def choice(self) -> Callable[[Sequence[_KT]], _KT]: ... + +class TTLCache(Cache[_KT, _VT]): + def __init__( + self, maxsize: float, ttl: float, timer: Callable[[], float] = ..., getsizeof: Callable[[_VT], float] | None = ... + ) -> None: ... + def __getitem__(self, key: _KT, cache_getitem: Callable[[_KT], _VT] = ...) -> _VT: ... + def __setitem__(self, key: _KT, value: _VT, cache_setitem: Callable[[_KT, _VT], None] = ...) -> None: ... + def __delitem__(self, key: _KT, cache_delitem: Callable[[_KT], None] = ...) -> None: ... + def __iter__(self) -> Iterator[_KT]: ... + def __len__(self) -> int: ... + @property + def currsize(self) -> float: ... + @property + def timer(self) -> Callable[[], float]: ... + @property + def ttl(self) -> float: ... + def expire(self, time: float | None = ...) -> None: ... + +def cached( + cache: MutableMapping[_KT, Any] | None, key: Callable[..., _KT] = ..., lock: ContextManager[Any] | None = ... +) -> IdentityFunction: ... +def cachedmethod( + cache: Callable[[Any], MutableMapping[_KT, Any] | None], key: Callable[..., _KT] = ..., lock: ContextManager[Any] | None = ... +) -> IdentityFunction: ... + diff --git a/stubs/cachetools/cachetools/fifo.pyi b/stubs/cachetools/cachetools/fifo.pyi new file mode 100644 index 000000000000..c6b386ad455a --- /dev/null +++ b/stubs/cachetools/cachetools/fifo.pyi @@ -0,0 +1,2 @@ +# this module is deprecated +from . import FIFOCache as FIFOCache diff --git a/stubs/cachetools/cachetools/lfu.pyi b/stubs/cachetools/cachetools/lfu.pyi index e63aeb313628..9951e65e2841 100644 --- a/stubs/cachetools/cachetools/lfu.pyi +++ b/stubs/cachetools/cachetools/lfu.pyi @@ -1,14 +1,2 @@ -from typing import Callable, Iterator, TypeVar - -from .cache import Cache - -_KT = TypeVar("_KT") -_VT = TypeVar("_VT") - -class LFUCache(Cache[_KT, _VT]): - def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ... - def __getitem__(self, key: _KT, cache_getitem: Callable[[_KT], _VT] = ...) -> _VT: ... - def __setitem__(self, key: _KT, value: _VT, cache_setitem: Callable[[_KT, _VT], None] = ...) -> None: ... - def __delitem__(self, key: _KT, cache_delitem: Callable[[_KT], None] = ...) -> None: ... - def __iter__(self) -> Iterator[_KT]: ... - def __len__(self) -> int: ... +# this module is deprecated +from . import LFUCache as LFUCache diff --git a/stubs/cachetools/cachetools/lru.pyi b/stubs/cachetools/cachetools/lru.pyi index 128a91480aff..4ea2d6413ca6 100644 --- a/stubs/cachetools/cachetools/lru.pyi +++ b/stubs/cachetools/cachetools/lru.pyi @@ -1,13 +1,2 @@ -from typing import Callable, Iterator, TypeVar - -from .cache import Cache as Cache - -_KT = TypeVar("_KT") -_VT = TypeVar("_VT") - -class LRUCache(Cache[_KT, _VT]): - def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ... - def __getitem__(self, key: _KT, cache_getitem: Callable[[_KT], _VT] = ...) -> _VT: ... - def __setitem__(self, key: _KT, value: _VT, cache_setitem: Callable[[_KT, _VT], None] = ...) -> None: ... - def __delitem__(self, key: _KT, cache_delitem: Callable[[_KT], None] = ...) -> None: ... - def __iter__(self) -> Iterator[_KT]: ... +# this module is deprecated +from . import LRUCache as LRUCache diff --git a/stubs/cachetools/cachetools/mru.pyi b/stubs/cachetools/cachetools/mru.pyi new file mode 100644 index 000000000000..aee05857648a --- /dev/null +++ b/stubs/cachetools/cachetools/mru.pyi @@ -0,0 +1,2 @@ +# this module is deprecated +from . import TTLCache as TTLCache diff --git a/stubs/cachetools/cachetools/rr.pyi b/stubs/cachetools/cachetools/rr.pyi index aa4190d047c2..18e2098ceb66 100644 --- a/stubs/cachetools/cachetools/rr.pyi +++ b/stubs/cachetools/cachetools/rr.pyi @@ -1,18 +1,2 @@ -from typing import Callable, Iterator, Sequence, TypeVar - -from .cache import Cache as Cache - -_KT = TypeVar("_KT") -_VT = TypeVar("_VT") - -class RRCache(Cache[_KT, _VT]): - def __init__( - self, maxsize: float, choice: Callable[[Sequence[_KT]], _KT] | None = ..., 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: ... - def __iter__(self) -> Iterator[_KT]: ... - def __len__(self) -> int: ... - @property - def choice(self) -> Callable[[Sequence[_KT]], _KT]: ... +# this module is deprecated +from . import RRCache as RRCache From 902bc24804133e8f1d95397e8a495182adcfaff5 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 30 Sep 2021 16:32:35 +0300 Subject: [PATCH 07/12] add stubgen-generated stubs to FIFOCache and MRUCache --- stubs/cachetools/cachetools/__init__.pyi | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index 3adad0320481..0138e46579e4 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -27,7 +27,11 @@ class Cache(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def getsizeof(value: _VT) -> float: ... class FIFOCache(Cache[_KT, _VT]): - pass # TODO + # TODO: add types to these, generated by stubgen + def __init__(self, maxsize, getsizeof: Any | None = ...) -> None: ... + def __setitem__(self, key, value, cache_setitem=...) -> None: ... + def __delitem__(self, key, cache_delitem=...) -> None: ... + def popitem(self): ... class LFUCache(Cache[_KT, _VT]): def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ... @@ -45,7 +49,12 @@ class LRUCache(Cache[_KT, _VT]): def __iter__(self) -> Iterator[_KT]: ... class MRUCache(Cache[_KT, _VT]): - pass # TODO + # TODO: add types to these, generated by stubgen + def __init__(self, maxsize, getsizeof: Any | None = ...) -> None: ... + def __getitem__(self, key, cache_getitem=...): ... + def __setitem__(self, key, value, cache_setitem=...) -> None: ... + def __delitem__(self, key, cache_delitem=...) -> None: ... + def popitem(self): ... class RRCache(Cache[_KT, _VT]): def __init__( From e3987543fb9580a6fcf8268f5390d8f75107d8fd Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 30 Sep 2021 16:36:32 +0300 Subject: [PATCH 08/12] add types to FooCache classes and delete methods that are not overrided at runtime --- stubs/cachetools/cachetools/__init__.pyi | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index 0138e46579e4..c71bd5ea1ca0 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -27,8 +27,8 @@ class Cache(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def getsizeof(value: _VT) -> float: ... class FIFOCache(Cache[_KT, _VT]): + def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ... # TODO: add types to these, generated by stubgen - def __init__(self, maxsize, getsizeof: Any | None = ...) -> None: ... def __setitem__(self, key, value, cache_setitem=...) -> None: ... def __delitem__(self, key, cache_delitem=...) -> None: ... def popitem(self): ... @@ -38,19 +38,16 @@ class LFUCache(Cache[_KT, _VT]): def __getitem__(self, key: _KT, cache_getitem: Callable[[_KT], _VT] = ...) -> _VT: ... def __setitem__(self, key: _KT, value: _VT, cache_setitem: Callable[[_KT, _VT], None] = ...) -> None: ... def __delitem__(self, key: _KT, cache_delitem: Callable[[_KT], None] = ...) -> None: ... - def __iter__(self) -> Iterator[_KT]: ... - def __len__(self) -> int: ... class LRUCache(Cache[_KT, _VT]): def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ... def __getitem__(self, key: _KT, cache_getitem: Callable[[_KT], _VT] = ...) -> _VT: ... def __setitem__(self, key: _KT, value: _VT, cache_setitem: Callable[[_KT, _VT], None] = ...) -> None: ... def __delitem__(self, key: _KT, cache_delitem: Callable[[_KT], None] = ...) -> None: ... - def __iter__(self) -> Iterator[_KT]: ... class MRUCache(Cache[_KT, _VT]): + def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ... # TODO: add types to these, generated by stubgen - def __init__(self, maxsize, getsizeof: Any | None = ...) -> None: ... def __getitem__(self, key, cache_getitem=...): ... def __setitem__(self, key, value, cache_setitem=...) -> None: ... def __delitem__(self, key, cache_delitem=...) -> None: ... @@ -60,11 +57,6 @@ class RRCache(Cache[_KT, _VT]): def __init__( self, maxsize: float, choice: Callable[[Sequence[_KT]], _KT] | None = ..., 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: ... - def __iter__(self) -> Iterator[_KT]: ... - def __len__(self) -> int: ... @property def choice(self) -> Callable[[Sequence[_KT]], _KT]: ... From dc6152171b934a3f182377d2f36601fac36ddf6a Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 30 Sep 2021 16:38:10 +0300 Subject: [PATCH 09/12] comment out untyped methods that can be inherited from MutableMapping --- stubs/cachetools/cachetools/__init__.pyi | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index c71bd5ea1ca0..d71ba827674d 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -28,10 +28,10 @@ class Cache(MutableMapping[_KT, _VT], Generic[_KT, _VT]): class FIFOCache(Cache[_KT, _VT]): def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ... - # TODO: add types to these, generated by stubgen - def __setitem__(self, key, value, cache_setitem=...) -> None: ... - def __delitem__(self, key, cache_delitem=...) -> None: ... - def popitem(self): ... + # TODO: add types to these, currently using what is defined in superclass + #def __setitem__(self, key, value, cache_setitem=...) -> None: ... + #def __delitem__(self, key, cache_delitem=...) -> None: ... + #def popitem(self): ... class LFUCache(Cache[_KT, _VT]): def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ... @@ -47,11 +47,11 @@ class LRUCache(Cache[_KT, _VT]): class MRUCache(Cache[_KT, _VT]): def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ... - # TODO: add types to these, generated by stubgen - def __getitem__(self, key, cache_getitem=...): ... - def __setitem__(self, key, value, cache_setitem=...) -> None: ... - def __delitem__(self, key, cache_delitem=...) -> None: ... - def popitem(self): ... + # TODO: add types to these, currently using what is defined in superclass + #def __getitem__(self, key, cache_getitem=...): ... + #def __setitem__(self, key, value, cache_setitem=...) -> None: ... + #def __delitem__(self, key, cache_delitem=...) -> None: ... + #def popitem(self): ... class RRCache(Cache[_KT, _VT]): def __init__( From 5674e1166f0cd18cfac02bd3fc72aba520a5becb Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 30 Sep 2021 16:48:06 +0300 Subject: [PATCH 10/12] running stubtest --- .../cachetools/@tests/stubtest_allowlist.txt | 5 ---- stubs/cachetools/cachetools/__init__.pyi | 9 ++----- stubs/cachetools/cachetools/mru.pyi | 2 +- stubs/cachetools/cachetools/ttl.pyi | 25 ++----------------- 4 files changed, 5 insertions(+), 36 deletions(-) diff --git a/stubs/cachetools/@tests/stubtest_allowlist.txt b/stubs/cachetools/@tests/stubtest_allowlist.txt index b041adaf5ce4..131ef5b94237 100644 --- a/stubs/cachetools/@tests/stubtest_allowlist.txt +++ b/stubs/cachetools/@tests/stubtest_allowlist.txt @@ -8,19 +8,14 @@ cachetools.LRUCache.__setitem__ cachetools.TTLCache.__delitem__ cachetools.TTLCache.__getitem__ cachetools.TTLCache.__setitem__ -cachetools.abc cachetools.cache.Cache.get -cachetools.cache.DefaultMapping cachetools.func.ttl_cache cachetools.lfu.LFUCache.__delitem__ cachetools.lfu.LFUCache.__getitem__ cachetools.lfu.LFUCache.__setitem__ -cachetools.lru.Cache.get cachetools.lru.LRUCache.__delitem__ cachetools.lru.LRUCache.__getitem__ cachetools.lru.LRUCache.__setitem__ -cachetools.rr.Cache.get -cachetools.ttl.Cache.get cachetools.ttl.TTLCache.__delitem__ cachetools.ttl.TTLCache.__getitem__ cachetools.ttl.TTLCache.__setitem__ diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index d71ba827674d..4e3dfa81a5da 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -1,10 +1,5 @@ -from .decorators import cached as cached, cachedmethod as cachedmethod -from .lfu import LFUCache as LFUCache -from .lru import LRUCache as LRUCache -from .rr import RRCache as RRCache -from .ttl import TTLCache as TTLCache - -from typing import Callable, Generic, Iterator, TypeVar +from collections.abc import Iterator, Sequence +from typing import Callable, Generic, TypeVar from _typeshed import IdentityFunction from typing import Any, Callable, ContextManager, MutableMapping, TypeVar diff --git a/stubs/cachetools/cachetools/mru.pyi b/stubs/cachetools/cachetools/mru.pyi index aee05857648a..b345f5262b04 100644 --- a/stubs/cachetools/cachetools/mru.pyi +++ b/stubs/cachetools/cachetools/mru.pyi @@ -1,2 +1,2 @@ # this module is deprecated -from . import TTLCache as TTLCache +from . import MRUCache as MRUCache diff --git a/stubs/cachetools/cachetools/ttl.pyi b/stubs/cachetools/cachetools/ttl.pyi index 12cd6072cdfb..aee05857648a 100644 --- a/stubs/cachetools/cachetools/ttl.pyi +++ b/stubs/cachetools/cachetools/ttl.pyi @@ -1,23 +1,2 @@ -from typing import Callable, Iterator, TypeVar - -from .cache import Cache as Cache - -_KT = TypeVar("_KT") -_VT = TypeVar("_VT") - -class TTLCache(Cache[_KT, _VT]): - def __init__( - self, maxsize: float, ttl: float, timer: Callable[[], float] = ..., getsizeof: Callable[[_VT], float] | None = ... - ) -> None: ... - def __getitem__(self, key: _KT, cache_getitem: Callable[[_KT], _VT] = ...) -> _VT: ... - def __setitem__(self, key: _KT, value: _VT, cache_setitem: Callable[[_KT, _VT], None] = ...) -> None: ... - def __delitem__(self, key: _KT, cache_delitem: Callable[[_KT], None] = ...) -> None: ... - def __iter__(self) -> Iterator[_KT]: ... - def __len__(self) -> int: ... - @property - def currsize(self) -> float: ... - @property - def timer(self) -> Callable[[], float]: ... - @property - def ttl(self) -> float: ... - def expire(self, time: float | None = ...) -> None: ... +# this module is deprecated +from . import TTLCache as TTLCache From faf3fb754f6916594d9e23351b0f1c8cfb0e4094 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 30 Sep 2021 16:51:43 +0300 Subject: [PATCH 11/12] black and isort --- stubs/cachetools/cachetools/__init__.pyi | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/stubs/cachetools/cachetools/__init__.pyi b/stubs/cachetools/cachetools/__init__.pyi index 4e3dfa81a5da..58a119274f40 100644 --- a/stubs/cachetools/cachetools/__init__.pyi +++ b/stubs/cachetools/cachetools/__init__.pyi @@ -1,8 +1,6 @@ -from collections.abc import Iterator, Sequence -from typing import Callable, Generic, TypeVar - from _typeshed import IdentityFunction -from typing import Any, Callable, ContextManager, MutableMapping, TypeVar +from collections.abc import Iterator, Sequence +from typing import Any, Callable, ContextManager, Generic, MutableMapping, TypeVar _KT = TypeVar("_KT") _VT = TypeVar("_VT") @@ -24,9 +22,9 @@ class Cache(MutableMapping[_KT, _VT], Generic[_KT, _VT]): class FIFOCache(Cache[_KT, _VT]): def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ... # TODO: add types to these, currently using what is defined in superclass - #def __setitem__(self, key, value, cache_setitem=...) -> None: ... - #def __delitem__(self, key, cache_delitem=...) -> None: ... - #def popitem(self): ... + # def __setitem__(self, key, value, cache_setitem=...) -> None: ... + # def __delitem__(self, key, cache_delitem=...) -> None: ... + # def popitem(self): ... class LFUCache(Cache[_KT, _VT]): def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ... @@ -43,10 +41,10 @@ class LRUCache(Cache[_KT, _VT]): class MRUCache(Cache[_KT, _VT]): def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = ...) -> None: ... # TODO: add types to these, currently using what is defined in superclass - #def __getitem__(self, key, cache_getitem=...): ... - #def __setitem__(self, key, value, cache_setitem=...) -> None: ... - #def __delitem__(self, key, cache_delitem=...) -> None: ... - #def popitem(self): ... + # def __getitem__(self, key, cache_getitem=...): ... + # def __setitem__(self, key, value, cache_setitem=...) -> None: ... + # def __delitem__(self, key, cache_delitem=...) -> None: ... + # def popitem(self): ... class RRCache(Cache[_KT, _VT]): def __init__( @@ -78,4 +76,3 @@ def cached( def cachedmethod( cache: Callable[[Any], MutableMapping[_KT, Any] | None], key: Callable[..., _KT] = ..., lock: ContextManager[Any] | None = ... ) -> IdentityFunction: ... - From a99449ddc938cf9fce4b0186ab6518e6382024a1 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 30 Sep 2021 17:17:06 +0300 Subject: [PATCH 12/12] fix ttl_cache timer --- stubs/cachetools/@tests/stubtest_allowlist.txt | 1 - stubs/cachetools/cachetools/func.pyi | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/stubs/cachetools/@tests/stubtest_allowlist.txt b/stubs/cachetools/@tests/stubtest_allowlist.txt index 131ef5b94237..2273f0b16f68 100644 --- a/stubs/cachetools/@tests/stubtest_allowlist.txt +++ b/stubs/cachetools/@tests/stubtest_allowlist.txt @@ -9,7 +9,6 @@ cachetools.TTLCache.__delitem__ cachetools.TTLCache.__getitem__ cachetools.TTLCache.__setitem__ cachetools.cache.Cache.get -cachetools.func.ttl_cache cachetools.lfu.LFUCache.__delitem__ cachetools.lfu.LFUCache.__getitem__ cachetools.lfu.LFUCache.__setitem__ diff --git a/stubs/cachetools/cachetools/func.pyi b/stubs/cachetools/cachetools/func.pyi index 1ae2d8f3b1eb..d081d5166316 100644 --- a/stubs/cachetools/cachetools/func.pyi +++ b/stubs/cachetools/cachetools/func.pyi @@ -8,4 +8,6 @@ def lfu_cache(maxsize: float = ..., typed: bool = ...) -> IdentityFunction: ... def lru_cache(maxsize: float = ..., typed: bool = ...) -> IdentityFunction: ... def mru_cache(maxsize: float = ..., typed: bool = ...) -> IdentityFunction: ... def rr_cache(maxsize: float = ..., choice: Callable[[Sequence[_T]], _T] | None = ..., typed: bool = ...) -> IdentityFunction: ... -def ttl_cache(maxsize: float = ..., ttl: float = ..., timer: float = ..., typed: bool = ...) -> IdentityFunction: ... +def ttl_cache( + maxsize: float = ..., ttl: float = ..., timer: Callable[[], float] = ..., typed: bool = ... +) -> IdentityFunction: ...