@@ -39,7 +39,7 @@ def __bool__(self) -> bool:
3939
4040 logger = config .debug_printer ("memcache" )
4141
42- def __init__ (self , servers , debug : bool = False ) -> None :
42+ def __init__ (self , servers : str | list [ str ] , debug : bool = False ) -> None :
4343 """Create a memcached client.
4444
4545 Args:
@@ -58,7 +58,7 @@ def __bool__(self) -> bool:
5858 return bool (self .servers )
5959
6060 @property
61- def client (self ):
61+ def client (self ) -> Client_ :
6262 """Get the native memcache client.
6363
6464 Returns:
@@ -68,7 +68,7 @@ def client(self):
6868 self ._client = Client_ (self .servers )
6969 return self ._client
7070
71- def test_servers (self ):
71+ def test_servers (self ) -> set [ str ] :
7272 """Test that memcached servers are servicing requests.
7373
7474 Returns:
@@ -83,7 +83,7 @@ def test_servers(self):
8383 responders .add (server )
8484 return responders
8585
86- def set (self , key , val , time : int = 0 , min_compress_len : int = 0 ) -> None :
86+ def set (self , key : str , val : Any , time : int = 0 , min_compress_len : int = 0 ) -> None :
8787 """See memcache.Client."""
8888 if not self .servers :
8989 return
@@ -98,7 +98,7 @@ def set(self, key, val, time: int=0, min_compress_len: int=0) -> None:
9898 min_compress_len = min_compress_len )
9999 self .logger ("SET: %s" , key )
100100
101- def get (self , key ) :
101+ def get (self , key : str ) -> Any | Client . _Miss :
102102 """See memcache.Client.
103103
104104 Returns:
@@ -122,7 +122,7 @@ def get(self, key):
122122 self .logger ("MISS: %s" , key )
123123 return self .miss
124124
125- def delete (self , key ) -> None :
125+ def delete (self , key : str ) -> None :
126126 """See memcache.Client."""
127127 if self .servers :
128128 key = self ._qualified_key (key )
@@ -149,7 +149,7 @@ def flush(self, hard: bool = False) -> None:
149149 tag = "flushed" + tag
150150 self .current = tag
151151
152- def get_stats (self ):
152+ def get_stats (self ) -> list [ tuple ] :
153153 """Get server statistics.
154154
155155 Returns:
@@ -167,7 +167,7 @@ def disconnect(self) -> None:
167167 self ._client .disconnect_all ()
168168 # print("Disconnected memcached client %s" % str(self))
169169
170- def _qualified_key (self , key ) -> str :
170+ def _qualified_key (self , key : str ) -> str :
171171 """
172172 Qualify cache key so that:
173173 * changes to schemas don't break compatibility (cache_interface_version)
@@ -181,15 +181,15 @@ def _qualified_key(self, key) -> str:
181181 key
182182 )
183183
184- def _get_stats (self , stat_args = None ):
184+ def _get_stats (self , stat_args = None ) -> list [ tuple ] :
185185 return self .client .get_stats (stat_args = stat_args )
186186
187187 @classmethod
188- def _key_hash (cls , key ) :
188+ def _key_hash (cls , key : str ) -> str :
189189 return md5 (key .encode ("utf-8" )).hexdigest ()
190190
191191 @classmethod
192- def _debug_key_hash (cls , key ) :
192+ def _debug_key_hash (cls , key : str ) -> str :
193193 import re
194194 h = cls ._key_hash (key )[:16 ]
195195 value = "%s:%s" % (h , key )
@@ -213,7 +213,7 @@ def acquire(self, servers, debug: bool = False) -> tuple[Client, tuple[tuple, bo
213213 self .clients [key ] = [client , 1 ]
214214 return client , key
215215
216- def release (self , key ) -> None :
216+ def release (self , key : tuple [ tuple , bool ] ) -> None :
217217 entry = self .clients .get (key )
218218 assert entry
219219
@@ -405,5 +405,5 @@ def forget() -> None:
405405
406406
407407class DoNotCache (object ):
408- def __init__ (self , result ) -> None :
408+ def __init__ (self , result : Any ) -> None :
409409 self .result = result
0 commit comments