Skip to content

Commit b3def3b

Browse files
committed
[cachetools] Update to 7.0.* (#15357)
1 parent eec9fe9 commit b3def3b

File tree

4 files changed

+80
-54
lines changed

4 files changed

+80
-54
lines changed

stubs/cachetools/@tests/stubtest_allowlist.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ cachetools.LFUCache.__setitem__
99
cachetools.LRUCache.__delitem__
1010
cachetools.LRUCache.__getitem__
1111
cachetools.LRUCache.__setitem__
12+
cachetools.RRCache.__delitem__
13+
cachetools.RRCache.__setitem__
1214
cachetools.TLRUCache.__delitem__
1315
cachetools.TLRUCache.__getitem__
1416
cachetools.TLRUCache.__setitem__

stubs/cachetools/METADATA.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version = "6.2.*"
1+
version = "7.0.*"
22
upstream-repository = "https://github.com/tkem/cachetools"
Lines changed: 75 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
from _typeshed import IdentityFunction, Unused
21
from collections.abc import Callable, Iterator, MutableMapping, Sequence
32
from contextlib import AbstractContextManager
4-
from threading import Condition
5-
from typing import Any, Generic, Literal, NamedTuple, TypeVar, overload, type_check_only
6-
from typing_extensions import Self, deprecated
3+
from typing import Any, Final, Generic, Literal, NamedTuple, Protocol, TypeVar, overload, type_check_only
74

8-
__all__ = ("Cache", "FIFOCache", "LFUCache", "LRUCache", "RRCache", "TLRUCache", "TTLCache", "cached", "cachedmethod")
5+
__all__: Final = ("Cache", "FIFOCache", "LFUCache", "LRUCache", "RRCache", "TLRUCache", "TTLCache", "cached", "cachedmethod")
96
__version__: str
107

118
_KT = TypeVar("_KT")
129
_VT = TypeVar("_VT")
10+
_TT = TypeVar("_TT")
1311
_T = TypeVar("_T")
1412
_R = TypeVar("_R")
1513

1614
class Cache(MutableMapping[_KT, _VT]):
17-
@overload
18-
def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float]) -> None: ...
19-
@overload
20-
def __init__(self, maxsize: float, getsizeof: None = None) -> None: ...
15+
def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = None): ...
2116
def __getitem__(self, key: _KT) -> _VT: ...
2217
def __setitem__(self, key: _KT, value: _VT) -> None: ...
2318
def __delitem__(self, key: _KT) -> None: ...
@@ -53,104 +48,132 @@ class RRCache(Cache[_KT, _VT]):
5348
def __init__(self, maxsize: float, choice: Callable[[Sequence[_KT]], _KT], getsizeof: Callable[[_VT], float]) -> None: ...
5449
@property
5550
def choice(self) -> Callable[[Sequence[_KT]], _KT]: ...
56-
def __setitem__(self, key: _KT, value: _VT, cache_setitem: Callable[[Self, _KT, _VT], None] = ...) -> None: ...
57-
def __delitem__(self, key: _KT, cache_delitem: Callable[[Self, _KT], None] = ...) -> None: ...
5851

5952
class _TimedCache(Cache[_KT, _VT]):
6053
@overload
61-
def __init__(self, maxsize: float, timer: Callable[[], float] = ..., getsizeof: None = None) -> None: ...
54+
def __init__(self, maxsize: float, timer: Callable[[], _TT] = ..., getsizeof: None = None): ...
6255
@overload
63-
def __init__(self, maxsize: float, timer: Callable[[], float], getsizeof: Callable[[_VT], float]) -> None: ...
56+
def __init__(self, maxsize: float, timer: Callable[[], _TT], getsizeof: Callable[[_VT], float]): ...
6457
@overload
65-
def __init__(self, maxsize: float, timer: Callable[[], float] = ..., *, getsizeof: Callable[[_VT], float]) -> None: ...
66-
@property
67-
def currsize(self) -> float: ...
58+
def __init__(self, maxsize: float, timer: Callable[[], _TT] = ..., *, getsizeof: Callable[[_VT], float]): ...
6859

6960
class _Timer:
70-
def __init__(self, timer: Callable[[], float]) -> None: ...
71-
def __call__(self) -> float: ...
72-
def __enter__(self) -> float: ...
73-
def __exit__(self, *exc: Unused) -> None: ...
61+
def __init__(self, timer: Callable[[], _TT]) -> None: ...
62+
def __call__(self) -> Any: ...
63+
def __enter__(self) -> Any: ...
64+
def __exit__(self, *exc: object) -> None: ...
65+
def __getattr__(self, name: str) -> Any: ...
7466

7567
@property
7668
def timer(self) -> _Timer: ...
7769

7870
class TTLCache(_TimedCache[_KT, _VT]):
7971
@overload
80-
def __init__(self, maxsize: float, ttl: float, timer: Callable[[], float] = ..., getsizeof: None = None) -> None: ...
72+
def __init__(self, maxsize: float, ttl: Any, timer: Callable[..., _TT] = ..., getsizeof: None = None): ...
8173
@overload
82-
def __init__(self, maxsize: float, ttl: float, timer: Callable[[], float], getsizeof: Callable[[_VT], float]) -> None: ...
74+
def __init__(self, maxsize: float, ttl: Any, timer: Callable[..., _TT], getsizeof: Callable[[_VT], float]): ...
8375
@overload
84-
def __init__(
85-
self, maxsize: float, ttl: float, timer: Callable[[], float] = ..., *, getsizeof: Callable[[_VT], float]
86-
) -> None: ...
76+
def __init__(self, maxsize: float, ttl: Any, timer: Callable[..., _TT] = ..., *, getsizeof: Callable[[_VT], float]): ...
8777
@property
88-
def ttl(self) -> float: ...
89-
def expire(self, time: float | None = None) -> list[tuple[_KT, _VT]]: ...
78+
def ttl(self) -> Any: ...
79+
def expire(self, time: Any | None = None) -> list[tuple[_KT, _VT]]: ...
9080

9181
class TLRUCache(_TimedCache[_KT, _VT]):
82+
@overload
83+
def __init__(
84+
self, maxsize: float, ttu: Callable[[_KT, _VT, _TT], _TT], timer: Callable[..., _TT] = ..., getsizeof: None = None
85+
): ...
86+
@overload
87+
def __init__(
88+
self, maxsize: float, ttu: Callable[[_KT, _VT, _TT], _TT], timer: Callable[..., _TT], getsizeof: Callable[[_VT], float]
89+
): ...
90+
@overload
9291
def __init__(
9392
self,
9493
maxsize: float,
95-
ttu: Callable[[_KT, _VT, float], float],
96-
timer: Callable[[], float] = ...,
97-
getsizeof: Callable[[_VT], float] | None = None,
98-
) -> None: ...
94+
ttu: Callable[[_KT, _VT, _TT], _TT],
95+
timer: Callable[..., _TT] = ...,
96+
*,
97+
getsizeof: Callable[[_VT], float],
98+
): ...
9999
@property
100-
def ttu(self) -> Callable[[_KT, _VT, float], float]: ...
101-
def expire(self, time: float | None = None) -> list[tuple[_KT, _VT]]: ...
100+
def ttu(self) -> Callable[[_KT, _VT, _TT], _TT]: ...
101+
def expire(self, time: Any | None = None) -> list[tuple[_KT, _VT]]: ...
102102

103103
class _CacheInfo(NamedTuple):
104104
hits: int
105105
misses: int
106106
maxsize: int | None
107107
currsize: int
108108

109+
@type_check_only
110+
class _AbstractCondition(AbstractContextManager[Any], Protocol):
111+
# def wait(self, timeout: float | None = None) -> bool: ...
112+
def wait_for(self, predicate: Callable[[], _T], timeout: float | None = None) -> _T: ...
113+
# def notify(self, n: int = 1) -> None: ...
114+
def notify_all(self) -> None: ...
115+
109116
@type_check_only
110117
class _cached_wrapper(Generic[_R]):
111118
__wrapped__: Callable[..., _R]
119+
__name__: str
120+
__doc__: str | None
121+
cache: MutableMapping[Any, Any] | None
122+
cache_key: Callable[..., Any] = ...
123+
cache_lock: AbstractContextManager[Any] | None = None
124+
cache_condition: _AbstractCondition | None = None
112125
def __call__(self, /, *args: Any, **kwargs: Any) -> _R: ...
126+
def cache_clear(self) -> None: ...
113127

114128
@type_check_only
115129
class _cached_wrapper_info(_cached_wrapper[_R]):
116130
def cache_info(self) -> _CacheInfo: ...
117-
def cache_clear(self) -> None: ...
118131

119132
@overload
120133
def cached(
121134
cache: MutableMapping[_KT, Any] | None,
122135
key: Callable[..., _KT] = ...,
123136
lock: AbstractContextManager[Any] | None = None,
124-
condition: Condition | None = None,
137+
condition: _AbstractCondition | None = None,
125138
info: Literal[True] = ...,
126139
) -> Callable[[Callable[..., _R]], _cached_wrapper_info[_R]]: ...
127140
@overload
128141
def cached(
129142
cache: MutableMapping[_KT, Any] | None,
130143
key: Callable[..., _KT] = ...,
131144
lock: AbstractContextManager[Any] | None = None,
132-
condition: Condition | None = None,
145+
condition: _AbstractCondition | None = None,
133146
info: Literal[False] = ...,
134147
) -> Callable[[Callable[..., _R]], _cached_wrapper[_R]]: ...
148+
@type_check_only
149+
class _cachedmethod_wrapper(Generic[_R]):
150+
__wrapped__: Callable[..., _R]
151+
__name__: str
152+
__doc__: str | None
153+
cache: MutableMapping[Any, Any] | None
154+
cache_key: Callable[..., Any] = ...
155+
cache_lock: AbstractContextManager[Any] | None = None
156+
cache_condition: _AbstractCondition | None = None
157+
def __call__(self, obj, /, *args: Any, **kwargs: Any) -> _R: ...
158+
def cache_clear(self) -> None: ...
159+
160+
@type_check_only
161+
class _cachedmethod_wrapper_info(_cachedmethod_wrapper[_R]):
162+
def cache_info(self) -> _CacheInfo: ...
163+
135164
@overload
136-
@deprecated("Passing `info` as positional parameter is deprecated.")
137-
def cached(
138-
cache: MutableMapping[_KT, Any] | None,
165+
def cachedmethod(
166+
cache: Callable[[Any], MutableMapping[_KT, Any]],
139167
key: Callable[..., _KT] = ...,
140-
lock: AbstractContextManager[Any] | None = None,
141-
condition: Literal[True] = ...,
142-
) -> Callable[[Callable[..., _R]], _cached_wrapper_info[_R]]: ...
168+
lock: Callable[[Any], AbstractContextManager[Any]] | None = None,
169+
condition: Callable[[Any], _AbstractCondition] | None = None,
170+
info: Literal[True] = ...,
171+
) -> Callable[[Callable[..., _R]], _cachedmethod_wrapper_info[_R]]: ...
143172
@overload
144-
@deprecated("Passing `info` as positional parameter is deprecated.")
145-
def cached(
146-
cache: MutableMapping[_KT, Any] | None,
147-
key: Callable[..., _KT] = ...,
148-
lock: AbstractContextManager[Any] | None = None,
149-
condition: Literal[False] | None = ...,
150-
) -> Callable[[Callable[..., _R]], _cached_wrapper[_R]]: ...
151173
def cachedmethod(
152-
cache: Callable[[Any], MutableMapping[_KT, Any] | None],
174+
cache: Callable[[Any], MutableMapping[_KT, Any]],
153175
key: Callable[..., _KT] = ...,
154176
lock: Callable[[Any], AbstractContextManager[Any]] | None = None,
155-
condition: Condition | None = None,
156-
) -> IdentityFunction: ...
177+
condition: Callable[[Any], _AbstractCondition] | None = None,
178+
info: Literal[False] = ...,
179+
) -> Callable[[Callable[..., _R]], _cachedmethod_wrapper[_R]]: ...

stubs/cachetools/cachetools/keys.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from _typeshed import Unused
22
from collections.abc import Hashable
3+
from typing import Final
34

4-
__all__ = ("hashkey", "methodkey", "typedkey", "typedmethodkey")
5+
__all__: Final = ("hashkey", "methodkey", "typedkey", "typedmethodkey")
56

67
def hashkey(*args: Hashable, **kwargs: Hashable) -> tuple[Hashable, ...]: ...
78
def methodkey(self: Unused, /, *args: Hashable, **kwargs: Hashable) -> tuple[Hashable, ...]: ...

0 commit comments

Comments
 (0)