@@ -296,8 +296,10 @@ def set(self, key: T, value: U) -> None:
296296 node .val = value
297297 self .list .add (node )
298298
299- @staticmethod
300- def decorator (size : int = 128 ) -> Callable [[Callable [[T ], U ]], Callable [..., U ]]:
299+ @classmethod
300+ def decorator (
301+ cls , size : int = 128
302+ ) -> Callable [[Callable [[T ], U ]], Callable [..., U ]]:
301303 """
302304 Decorator version of LRU Cache
303305
@@ -306,19 +308,17 @@ def decorator(size: int = 128) -> Callable[[Callable[[T], U]], Callable[..., U]]
306308
307309 def cache_decorator_inner (func : Callable [[T ], U ]) -> Callable [..., U ]:
308310 def cache_decorator_wrapper (* args : T ) -> U :
309- if func not in LRUCache .decorator_function_to_instance_map :
310- LRUCache .decorator_function_to_instance_map [func ] = LRUCache (size )
311+ if func not in cls .decorator_function_to_instance_map :
312+ cls .decorator_function_to_instance_map [func ] = LRUCache (size )
311313
312- result = LRUCache .decorator_function_to_instance_map [func ].get (args [0 ])
314+ result = cls .decorator_function_to_instance_map [func ].get (args [0 ])
313315 if result is None :
314316 result = func (* args )
315- LRUCache .decorator_function_to_instance_map [func ].set (
316- args [0 ], result
317- )
317+ cls .decorator_function_to_instance_map [func ].set (args [0 ], result )
318318 return result
319319
320- def cache_info () -> LRUCache :
321- return LRUCache .decorator_function_to_instance_map [func ]
320+ def cache_info () -> LRUCache [ T , U ] :
321+ return cls .decorator_function_to_instance_map [func ]
322322
323323 setattr (cache_decorator_wrapper , "cache_info" , cache_info )
324324
0 commit comments