Skip to content

Commit eb4c33e

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

File tree

1 file changed

+12
-44
lines changed

1 file changed

+12
-44
lines changed

stubs/cachetools/cachetools/__init__.pyi

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from collections.abc import Callable, Iterator, MutableMapping, Sequence
22
from contextlib import AbstractContextManager
3+
import random
4+
import time
35
from typing import Any, Final, Generic, Literal, NamedTuple, Protocol, TypeVar, overload, type_check_only
46

57
__all__: Final = ("Cache", "FIFOCache", "LFUCache", "LRUCache", "RRCache", "TLRUCache", "TTLCache", "cached", "cachedmethod")
@@ -36,26 +38,12 @@ class LFUCache(Cache[_KT, _VT]): ...
3638
class LRUCache(Cache[_KT, _VT]): ...
3739

3840
class RRCache(Cache[_KT, _VT]):
39-
@overload
40-
def __init__(self, maxsize: float, choice: None = None, getsizeof: None = None) -> None: ...
41-
@overload
42-
def __init__(self, maxsize: float, *, getsizeof: Callable[[_VT], float]) -> None: ...
43-
@overload
44-
def __init__(self, maxsize: float, choice: None, getsizeof: Callable[[_VT], float]) -> None: ...
45-
@overload
46-
def __init__(self, maxsize: float, choice: Callable[[Sequence[_KT]], _KT], getsizeof: None = None) -> None: ...
47-
@overload
48-
def __init__(self, maxsize: float, choice: Callable[[Sequence[_KT]], _KT], getsizeof: Callable[[_VT], float]) -> None: ...
41+
def __init__(self, maxsize: float, choice: Callable[[Sequence[_KT]], _KT] = random.choice, getsizeof: Callable[[_VT], float] | None = None) -> None: ...
4942
@property
5043
def choice(self) -> Callable[[Sequence[_KT]], _KT]: ...
5144

52-
class _TimedCache(Cache[_KT, _VT]):
53-
@overload
54-
def __init__(self, maxsize: float, timer: Callable[[], _TT] = ..., getsizeof: None = None): ...
55-
@overload
56-
def __init__(self, maxsize: float, timer: Callable[[], _TT], getsizeof: Callable[[_VT], float]): ...
57-
@overload
58-
def __init__(self, maxsize: float, timer: Callable[[], _TT] = ..., *, getsizeof: Callable[[_VT], float]): ...
45+
class _TimedCache[_KT, _VT, _TT](Cache[_KT, _VT]):
46+
def __init__(self, maxsize: float, timer: Callable[..., _TT] = time.monotonic, getsizeof: Callable[[_VT], float] | None = None): ...
5947

6048
class _Timer:
6149
def __init__(self, timer: Callable[[], _TT]) -> None: ...
@@ -67,38 +55,18 @@ class _TimedCache(Cache[_KT, _VT]):
6755
@property
6856
def timer(self) -> _Timer: ...
6957

70-
class TTLCache(_TimedCache[_KT, _VT]):
71-
@overload
72-
def __init__(self, maxsize: float, ttl: Any, timer: Callable[..., _TT] = ..., getsizeof: None = None): ...
73-
@overload
74-
def __init__(self, maxsize: float, ttl: Any, timer: Callable[..., _TT], getsizeof: Callable[[_VT], float]): ...
75-
@overload
76-
def __init__(self, maxsize: float, ttl: Any, timer: Callable[..., _TT] = ..., *, getsizeof: Callable[[_VT], float]): ...
58+
# FIXME: ttl should be "addable" to _TT
59+
class TTLCache(_TimedCache[_KT, _VT, _TT]):
60+
def __init__(self, maxsize: float, ttl: Any, timer: Callable[..., _TT] = time.monotonic, getsizeof: Callable[[_VT], float] | None = None): ...
7761
@property
7862
def ttl(self) -> Any: ...
79-
def expire(self, time: Any | None = None) -> list[tuple[_KT, _VT]]: ...
63+
def expire(self, time: _TT | None = None) -> list[tuple[_KT, _VT]]: ...
8064

81-
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
91-
def __init__(
92-
self,
93-
maxsize: float,
94-
ttu: Callable[[_KT, _VT, _TT], _TT],
95-
timer: Callable[..., _TT] = ...,
96-
*,
97-
getsizeof: Callable[[_VT], float],
98-
): ...
65+
class TLRUCache(_TimedCache[_KT, _VT, _TT]):
66+
def __init__(self, maxsize: float, ttu: Callable[[_KT, _VT, _TT], _TT], timer: Callable[..., _TT] = time.monotonic, getsizeof: Callable[[_VT], float] | None = None): ...
9967
@property
10068
def ttu(self) -> Callable[[_KT, _VT, _TT], _TT]: ...
101-
def expire(self, time: Any | None = None) -> list[tuple[_KT, _VT]]: ...
69+
def expire(self, time: _TT | None = None) -> list[tuple[_KT, _VT]]: ...
10270

10371
class _CacheInfo(NamedTuple):
10472
hits: int

0 commit comments

Comments
 (0)