Skip to content

Commit 8abfe5d

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

File tree

3 files changed

+70
-61
lines changed

3 files changed

+70
-61
lines changed

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: 67 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
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
4+
from typing_extensions import Self
75

8-
__all__ = ("Cache", "FIFOCache", "LFUCache", "LRUCache", "RRCache", "TLRUCache", "TTLCache", "cached", "cachedmethod")
6+
from . import keys
7+
8+
__all__: Final = ("Cache", "FIFOCache", "LFUCache", "LRUCache", "RRCache", "TLRUCache", "TTLCache", "cached", "cachedmethod")
99
__version__: str
1010

1111
_KT = TypeVar("_KT")
1212
_VT = TypeVar("_VT")
13+
_TT = TypeVar("_TT")
1314
_T = TypeVar("_T")
1415
_R = TypeVar("_R")
1516

1617
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: ...
18+
def __init__(self, maxsize: float, getsizeof: Callable[[_VT], float] | None = None): ...
2119
def __getitem__(self, key: _KT) -> _VT: ...
2220
def __setitem__(self, key: _KT, value: _VT) -> None: ...
2321
def __delitem__(self, key: _KT) -> None: ...
@@ -53,104 +51,114 @@ class RRCache(Cache[_KT, _VT]):
5351
def __init__(self, maxsize: float, choice: Callable[[Sequence[_KT]], _KT], getsizeof: Callable[[_VT], float]) -> None: ...
5452
@property
5553
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: ...
5854

5955
class _TimedCache(Cache[_KT, _VT]):
60-
@overload
61-
def __init__(self, maxsize: float, timer: Callable[[], float] = ..., getsizeof: None = None) -> None: ...
62-
@overload
63-
def __init__(self, maxsize: float, timer: Callable[[], float], getsizeof: Callable[[_VT], float]) -> None: ...
64-
@overload
65-
def __init__(self, maxsize: float, timer: Callable[[], float] = ..., *, getsizeof: Callable[[_VT], float]) -> None: ...
66-
@property
67-
def currsize(self) -> float: ...
56+
def __init__(self, maxsize: float, timer: Callable[..., _TT], getsizeof: Callable[[_VT], float] | None): ...
6857

69-
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: ...
58+
class _Timer(AbstractContextManager[_TT]):
59+
def __call__(self) -> _TT: ...
60+
def __getattr__(self, name: str) -> Any: ...
7461

7562
@property
7663
def timer(self) -> _Timer: ...
7764

7865
class TTLCache(_TimedCache[_KT, _VT]):
7966
@overload
80-
def __init__(self, maxsize: float, ttl: float, timer: Callable[[], float] = ..., getsizeof: None = None) -> None: ...
67+
def __init__(self, maxsize: float, ttl: Any, timer: Callable[..., _TT] = ..., getsizeof: None = None): ...
8168
@overload
82-
def __init__(self, maxsize: float, ttl: float, timer: Callable[[], float], getsizeof: Callable[[_VT], float]) -> None: ...
69+
def __init__(self, maxsize: float, ttl: Any, timer: Callable[..., _TT], getsizeof: Callable[[_VT], float]): ...
8370
@overload
84-
def __init__(
85-
self, maxsize: float, ttl: float, timer: Callable[[], float] = ..., *, getsizeof: Callable[[_VT], float]
86-
) -> None: ...
71+
def __init__(self, maxsize: float, ttl: Any, timer: Callable[..., _TT] = ..., *, getsizeof: Callable[[_VT], float]): ...
8772
@property
88-
def ttl(self) -> float: ...
89-
def expire(self, time: float | None = None) -> list[tuple[_KT, _VT]]: ...
73+
def ttl(self) -> Any: ...
74+
def expire(self, time: _TT | None = None) -> list[tuple[_KT, _VT]]: ...
9075

9176
class TLRUCache(_TimedCache[_KT, _VT]):
92-
def __init__(
93-
self,
94-
maxsize: float,
95-
ttu: Callable[[_KT, _VT, float], float],
96-
timer: Callable[[], float] = ...,
97-
getsizeof: Callable[[_VT], float] | None = None,
98-
) -> None: ...
77+
@overload
78+
def __init__(self, maxsize: float, ttu: Callable[[_KT, _VT, _TT], _TT], timer: Callable[..., _TT] = ..., getsizeof: None = None): ...
79+
@overload
80+
def __init__(self, maxsize: float, ttu: Callable[[_KT, _VT, _TT], _TT], timer: Callable[..., _TT], getsizeof: Callable[[_VT], float]): ...
81+
@overload
82+
def __init__(self, maxsize: float, ttu: Callable[[_KT, _VT, _TT], _TT], timer: Callable[..., _TT] = ..., *, getsizeof: Callable[[_VT], float]): ...
9983
@property
100-
def ttu(self) -> Callable[[_KT, _VT, float], float]: ...
101-
def expire(self, time: float | None = None) -> list[tuple[_KT, _VT]]: ...
84+
def ttu(self) -> Callable[[_KT, _VT, _TT], _TT]: ...
85+
def expire(self, time: _TT | None = None) -> list[tuple[_KT, _VT]]: ...
10286

10387
class _CacheInfo(NamedTuple):
10488
hits: int
10589
misses: int
10690
maxsize: int | None
10791
currsize: int
10892

93+
@type_check_only
94+
class _AbstractCondition(AbstractContextManager[Any], Protocol):
95+
#def wait(self, timeout: float | None = None) -> bool: ...
96+
def wait_for(self, predicate: Callable[[], _T], timeout: float | None = None) -> _T: ...
97+
#def notify(self, n: int = 1) -> None: ...
98+
def notify_all(self) -> None: ...
99+
109100
@type_check_only
110101
class _cached_wrapper(Generic[_R]):
111102
__wrapped__: Callable[..., _R]
103+
__name__: str
104+
__doc__: str | None
105+
cache: MutableMapping[Any, Any] | None
106+
cache_key: Callable[..., Any] = ...
107+
cache_lock: AbstractContextManager[Any] | None = None
108+
cache_condition: _AbstractCondition | None = None
112109
def __call__(self, /, *args: Any, **kwargs: Any) -> _R: ...
110+
def cache_clear(self) -> None: ...
113111

114112
@type_check_only
115113
class _cached_wrapper_info(_cached_wrapper[_R]):
116114
def cache_info(self) -> _CacheInfo: ...
117-
def cache_clear(self) -> None: ...
118115

119116
@overload
120117
def cached(
121118
cache: MutableMapping[_KT, Any] | None,
122119
key: Callable[..., _KT] = ...,
123120
lock: AbstractContextManager[Any] | None = None,
124-
condition: Condition | None = None,
121+
condition: _AbstractCondition | None = None,
125122
info: Literal[True] = ...,
126123
) -> Callable[[Callable[..., _R]], _cached_wrapper_info[_R]]: ...
127124
@overload
128125
def cached(
129126
cache: MutableMapping[_KT, Any] | None,
130127
key: Callable[..., _KT] = ...,
131128
lock: AbstractContextManager[Any] | None = None,
132-
condition: Condition | None = None,
129+
condition: _AbstractCondition | None = None,
133130
info: Literal[False] = ...,
134131
) -> Callable[[Callable[..., _R]], _cached_wrapper[_R]]: ...
132+
133+
@type_check_only
134+
class _cachedmethod_wrapper(Generic[_R]):
135+
__wrapped__: Callable[..., _R]
136+
__name__: str
137+
__doc__: str | None
138+
cache: MutableMapping[Any, Any] | None
139+
cache_key: Callable[..., Any] = ...
140+
cache_lock: AbstractContextManager[Any] | None = None
141+
cache_condition: _AbstractCondition | None = None
142+
def __call__(self, obj, /, *args: Any, **kwargs: Any) -> _R: ...
143+
def cache_clear(self) -> None: ...
144+
145+
@type_check_only
146+
class _cachedmethod_wrapper_info(_cachedmethod_wrapper[_R]):
147+
def cache_info(self) -> _CacheInfo: ...
148+
135149
@overload
136-
@deprecated("Passing `info` as positional parameter is deprecated.")
137-
def cached(
138-
cache: MutableMapping[_KT, Any] | None,
150+
def cachedmethod(
151+
cache: Callable[[Any], MutableMapping[_KT, Any]],
139152
key: Callable[..., _KT] = ...,
140-
lock: AbstractContextManager[Any] | None = None,
141-
condition: Literal[True] = ...,
142-
) -> Callable[[Callable[..., _R]], _cached_wrapper_info[_R]]: ...
153+
lock: Callable[[Any], AbstractContextManager[Any]] | None = None,
154+
condition: Callable[[Any], _AbstractCondition] | None = None,
155+
info: Literal[True] = ...,
156+
) -> Callable[[Callable[..., _R]], _cachedmethod_wrapper_info[_R]]: ...
143157
@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]]: ...
151158
def cachedmethod(
152-
cache: Callable[[Any], MutableMapping[_KT, Any] | None],
159+
cache: Callable[[Any], MutableMapping[_KT, Any]],
153160
key: Callable[..., _KT] = ...,
154161
lock: Callable[[Any], AbstractContextManager[Any]] | None = None,
155-
condition: Condition | None = None,
156-
) -> IdentityFunction: ...
162+
condition: Callable[[Any], _AbstractCondition] | None = None,
163+
info: Literal[False] = ...,
164+
) -> 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)