@@ -2,15 +2,17 @@ from _typeshed import IdentityFunction, Unused
22from collections .abc import Callable , Iterator , MutableMapping , Sequence
33from contextlib import AbstractContextManager
44from threading import Condition
5- from typing import Any , TypeVar , overload
5+ from typing import Any , Generic , Literal , NamedTuple , TypeVar , overload
66from typing_extensions import Self , deprecated
77
88__all__ = ("Cache" , "FIFOCache" , "LFUCache" , "LRUCache" , "RRCache" , "TLRUCache" , "TTLCache" , "cached" , "cachedmethod" )
9+
910__version__ : str
1011
1112_KT = TypeVar ("_KT" )
1213_VT = TypeVar ("_VT" )
1314_T = TypeVar ("_T" )
15+ _R = TypeVar ("_R" )
1416
1517class Cache (MutableMapping [_KT , _VT ]):
1618 @overload
@@ -99,22 +101,61 @@ class TLRUCache(_TimedCache[_KT, _VT]):
99101 def ttu (self ) -> Callable [[_KT , _VT , float ], float ]: ...
100102 def expire (self , time : float | None = None ) -> list [tuple [_KT , _VT ]]: ...
101103
104+ class _CacheInfo (NamedTuple ):
105+ hits : int
106+ misses : int
107+ maxsize : int | None
108+ currsize : int
109+
110+ class _cached_wrapper (Generic [_R ]):
111+ __wrapped__ : Callable [..., _R ]
112+ def __call__ (self , / , * args : Any , ** kwargs : Any ) -> _R : ...
113+
114+ class _cached_wrapper_info (_cached_wrapper [_R ]):
115+ def cache_info (self ) -> _CacheInfo : ...
116+ def cache_clear (self ) -> None : ...
117+
102118@overload
103119def cached (
104120 cache : MutableMapping [_KT , Any ] | None ,
105121 key : Callable [..., _KT ] = ...,
106122 lock : AbstractContextManager [Any ] | None = None ,
107123 condition : Condition | None = None ,
108- info : bool = False ,
109- ) -> IdentityFunction : ...
124+ * ,
125+ info : Literal [True ],
126+ ) -> Callable [[Callable [..., _R ]], _cached_wrapper_info [_R ]]: ...
127+ @overload
128+ def cached (
129+ cache : MutableMapping [_KT , Any ] | None ,
130+ key : Callable [..., _KT ] = ...,
131+ lock : AbstractContextManager [Any ] | None = None ,
132+ condition : Condition | None = None ,
133+ * ,
134+ info : Literal [False ] = False ,
135+ ) -> Callable [[Callable [..., _R ]], _cached_wrapper [_R ]]: ...
136+ @overload
137+ def cached ( # без параметра info (по умолчанию False)
138+ cache : MutableMapping [_KT , Any ] | None ,
139+ key : Callable [..., _KT ] = ...,
140+ lock : AbstractContextManager [Any ] | None = None ,
141+ condition : Condition | None = None ,
142+ ) -> Callable [[Callable [..., _R ]], _cached_wrapper [_R ]]: ...
110143@overload
111144@deprecated ("Passing `info` as positional parameter is deprecated." )
112145def cached (
113146 cache : MutableMapping [_KT , Any ] | None ,
114147 key : Callable [..., _KT ] = ...,
115148 lock : AbstractContextManager [Any ] | None = None ,
116- condition : bool | None = None ,
117- ) -> IdentityFunction : ...
149+ condition : Literal [True ] = ...,
150+ ) -> Callable [[Callable [..., _R ]], _cached_wrapper_info [_R ]]: ...
151+ @overload
152+ @deprecated ("Passing `info` as positional parameter is deprecated." )
153+ def cached (
154+ cache : MutableMapping [_KT , Any ] | None ,
155+ key : Callable [..., _KT ] = ...,
156+ lock : AbstractContextManager [Any ] | None = None ,
157+ condition : Literal [False ] | None = ...,
158+ ) -> Callable [[Callable [..., _R ]], _cached_wrapper [_R ]]: ...
118159def cachedmethod (
119160 cache : Callable [[Any ], MutableMapping [_KT , Any ] | None ],
120161 key : Callable [..., _KT ] = ...,
0 commit comments