Skip to content

Commit 0a0d577

Browse files
committed
[mypy] Annotates lru_cache decorator for other/lru_cache
* Higher order functions require a verbose Callable annotation
1 parent edc55a0 commit 0a0d577

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Diff for: other/lru_cache.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -293,19 +293,20 @@ def set(self, key: int, value: int) -> None:
293293
self.list.add(node)
294294

295295
@staticmethod
296-
def decorator(size: int = 128):
296+
def decorator(size: int = 128) -> Callable[[Callable[[int], int]], Callable[..., int]]:
297297
"""
298298
Decorator version of LRU Cache
299-
"""
300299
301-
def cache_decorator_inner(func: Callable):
302-
def cache_decorator_wrapper(*args, **kwargs):
300+
Decorated function must be function of int -> int
301+
"""
302+
def cache_decorator_inner(func: Callable[[int], int]) -> Callable[..., int]:
303+
def cache_decorator_wrapper(*args: int) -> int:
303304
if func not in LRUCache.decorator_function_to_instance_map:
304305
LRUCache.decorator_function_to_instance_map[func] = LRUCache(size)
305306

306307
result = LRUCache.decorator_function_to_instance_map[func].get(args[0])
307308
if result is None:
308-
result = func(*args, **kwargs)
309+
result = func(*args)
309310
LRUCache.decorator_function_to_instance_map[func].set(
310311
args[0], result
311312
)

0 commit comments

Comments
 (0)