1- from collections .abc import Callable , Iterator , MutableMapping , Sequence
2- from contextlib import AbstractContextManager
31import random
42import time
3+ from collections .abc import Callable , Iterator , MutableMapping , Sequence
4+ from contextlib import AbstractContextManager
55from typing import Any , Final , Generic , Literal , NamedTuple , Protocol , TypeVar , overload , type_check_only
66
77__all__ : Final = ("Cache" , "FIFOCache" , "LFUCache" , "LRUCache" , "RRCache" , "TLRUCache" , "TTLCache" , "cached" , "cachedmethod" )
@@ -38,12 +38,19 @@ class LFUCache(Cache[_KT, _VT]): ...
3838class LRUCache (Cache [_KT , _VT ]): ...
3939
4040class RRCache (Cache [_KT , _VT ]):
41- def __init__ (self , maxsize : float , choice : Callable [[Sequence [_KT ]], _KT ] = random .choice , getsizeof : Callable [[_VT ], float ] | None = None ) -> None : ...
41+ def __init__ (
42+ self ,
43+ maxsize : float ,
44+ choice : Callable [[Sequence [_KT ]], _KT ] = random .choice ,
45+ getsizeof : Callable [[_VT ], float ] | None = None ,
46+ ) -> None : ...
4247 @property
4348 def choice (self ) -> Callable [[Sequence [_KT ]], _KT ]: ...
4449
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 ): ...
50+ class _TimedCache [KT , VT , TT ](Cache [KT , VT ]):
51+ def __init__ (
52+ self , maxsize : float , timer : Callable [..., _TT ] = time .monotonic , getsizeof : Callable [[_VT ], float ] | None = None
53+ ): ...
4754
4855 class _Timer :
4956 def __init__ (self , timer : Callable [[], _TT ]) -> None : ...
@@ -57,13 +64,25 @@ class _TimedCache[_KT, _VT, _TT](Cache[_KT, _VT]):
5764
5865# FIXME: ttl should be "addable" to _TT
5966class TTLCache (_TimedCache [_KT , _VT , _TT ]):
60- def __init__ (self , maxsize : float , ttl : Any , timer : Callable [..., _TT ] = time .monotonic , getsizeof : Callable [[_VT ], float ] | None = None ): ...
67+ def __init__ (
68+ self ,
69+ maxsize : float ,
70+ ttl : Any ,
71+ timer : Callable [..., _TT ] = time .monotonic ,
72+ getsizeof : Callable [[_VT ], float ] | None = None ,
73+ ): ...
6174 @property
6275 def ttl (self ) -> Any : ...
6376 def expire (self , time : _TT | None = None ) -> list [tuple [_KT , _VT ]]: ...
6477
6578class 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 ): ...
79+ def __init__ (
80+ self ,
81+ maxsize : float ,
82+ ttu : Callable [[_KT , _VT , _TT ], _TT ],
83+ timer : Callable [..., _TT ] = time .monotonic ,
84+ getsizeof : Callable [[_VT ], float ] | None = None ,
85+ ): ...
6786 @property
6887 def ttu (self ) -> Callable [[_KT , _VT , _TT ], _TT ]: ...
6988 def expire (self , time : _TT | None = None ) -> list [tuple [_KT , _VT ]]: ...
0 commit comments