@@ -294,8 +294,8 @@ def set(self, key: T, value: U) -> None:
294294 node .val = value
295295 self .list .add (node )
296296
297- @staticmethod
298- def decorator (size : int = 128 ) -> Callable [[Callable [[T ], U ]], Callable [..., U ]]:
297+ @classmethod
298+ def decorator (cls , size : int = 128 ) -> Callable [[Callable [[T ], U ]], Callable [..., U ]]:
299299 """
300300 Decorator version of LRU Cache
301301
@@ -304,19 +304,19 @@ def decorator(size: int = 128) -> Callable[[Callable[[T], U]], Callable[..., U]]
304304
305305 def cache_decorator_inner (func : Callable [[T ], U ]) -> Callable [..., U ]:
306306 def cache_decorator_wrapper (* args : T ) -> U :
307- if func not in LRUCache .decorator_function_to_instance_map :
308- LRUCache .decorator_function_to_instance_map [func ] = LRUCache (size )
307+ if func not in cls .decorator_function_to_instance_map :
308+ cls .decorator_function_to_instance_map [func ] = LRUCache (size )
309309
310- result = LRUCache .decorator_function_to_instance_map [func ].get (args [0 ])
310+ result = cls .decorator_function_to_instance_map [func ].get (args [0 ])
311311 if result is None :
312312 result = func (* args )
313- LRUCache .decorator_function_to_instance_map [func ].set (
313+ cls .decorator_function_to_instance_map [func ].set (
314314 args [0 ], result
315315 )
316316 return result
317317
318- def cache_info () -> LRUCache :
319- return LRUCache .decorator_function_to_instance_map [func ]
318+ def cache_info () -> LRUCache [ T , U ] :
319+ return cls .decorator_function_to_instance_map [func ]
320320
321321 setattr (cache_decorator_wrapper , "cache_info" , cache_info )
322322
0 commit comments