11from collections .abc import Callable , Iterator , MutableMapping , Sequence
22from contextlib import AbstractContextManager
33from typing import Any , Final , Generic , Literal , NamedTuple , Protocol , TypeVar , overload , type_check_only
4- from typing_extensions import Self
5-
6- from . import keys
74
85__all__ : Final = ("Cache" , "FIFOCache" , "LFUCache" , "LRUCache" , "RRCache" , "TLRUCache" , "TTLCache" , "cached" , "cachedmethod" )
96__version__ : str
@@ -53,10 +50,18 @@ class RRCache(Cache[_KT, _VT]):
5350 def choice (self ) -> Callable [[Sequence [_KT ]], _KT ]: ...
5451
5552class _TimedCache (Cache [_KT , _VT ]):
56- def __init__ (self , maxsize : float , timer : Callable [..., _TT ], getsizeof : Callable [[_VT ], float ] | None ): ...
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 ]): ...
5759
58- class _Timer (AbstractContextManager [_TT ]):
59- def __call__ (self ) -> _TT : ...
60+ class _Timer :
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 : ...
6065 def __getattr__ (self , name : str ) -> Any : ...
6166
6267 @property
@@ -71,18 +76,29 @@ class TTLCache(_TimedCache[_KT, _VT]):
7176 def __init__ (self , maxsize : float , ttl : Any , timer : Callable [..., _TT ] = ..., * , getsizeof : Callable [[_VT ], float ]): ...
7277 @property
7378 def ttl (self ) -> Any : ...
74- def expire (self , time : _TT | None = None ) -> list [tuple [_KT , _VT ]]: ...
79+ def expire (self , time : Any | None = None ) -> list [tuple [_KT , _VT ]]: ...
7580
7681class TLRUCache (_TimedCache [_KT , _VT ]):
7782 @overload
78- def __init__ (self , maxsize : float , ttu : Callable [[_KT , _VT , _TT ], _TT ], timer : Callable [..., _TT ] = ..., getsizeof : None = None ): ...
83+ def __init__ (
84+ self , maxsize : float , ttu : Callable [[_KT , _VT , _TT ], _TT ], timer : Callable [..., _TT ] = ..., getsizeof : None = None
85+ ): ...
7986 @overload
80- def __init__ (self , maxsize : float , ttu : Callable [[_KT , _VT , _TT ], _TT ], timer : Callable [..., _TT ], getsizeof : Callable [[_VT ], float ]): ...
87+ def __init__ (
88+ self , maxsize : float , ttu : Callable [[_KT , _VT , _TT ], _TT ], timer : Callable [..., _TT ], getsizeof : Callable [[_VT ], float ]
89+ ): ...
8190 @overload
82- def __init__ (self , maxsize : float , ttu : Callable [[_KT , _VT , _TT ], _TT ], timer : Callable [..., _TT ] = ..., * , getsizeof : Callable [[_VT ], float ]): ...
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+ ): ...
8399 @property
84100 def ttu (self ) -> Callable [[_KT , _VT , _TT ], _TT ]: ...
85- def expire (self , time : _TT | None = None ) -> list [tuple [_KT , _VT ]]: ...
101+ def expire (self , time : Any | None = None ) -> list [tuple [_KT , _VT ]]: ...
86102
87103class _CacheInfo (NamedTuple ):
88104 hits : int
@@ -92,9 +108,9 @@ class _CacheInfo(NamedTuple):
92108
93109@type_check_only
94110class _AbstractCondition (AbstractContextManager [Any ], Protocol ):
95- #def wait(self, timeout: float | None = None) -> bool: ...
111+ # def wait(self, timeout: float | None = None) -> bool: ...
96112 def wait_for (self , predicate : Callable [[], _T ], timeout : float | None = None ) -> _T : ...
97- #def notify(self, n: int = 1) -> None: ...
113+ # def notify(self, n: int = 1) -> None: ...
98114 def notify_all (self ) -> None : ...
99115
100116@type_check_only
@@ -129,7 +145,6 @@ def cached(
129145 condition : _AbstractCondition | None = None ,
130146 info : Literal [False ] = ...,
131147) -> Callable [[Callable [..., _R ]], _cached_wrapper [_R ]]: ...
132-
133148@type_check_only
134149class _cachedmethod_wrapper (Generic [_R ]):
135150 __wrapped__ : Callable [..., _R ]
0 commit comments