python-lru-cache

Python get the cache dictionary of _lru_cache_wrapper object

Python get the cache dictionary of _lru_cache_wrapper object Question: I have this simple cache decorator demo here @functools.cache def cached_fib(n): assert n > 0 if n <= 2: return 1 return cached_fib(n – 1) + cached_fib(n – 2) t1 = time.perf_counter() cached_fib(400) t2 = time.perf_counter() print(f"cached_fib: {t2 – t1}") # 0.0004117000003134308 I want to access …

Total answers: 2

TypeVar inference broken by lru_cache decorator

TypeVar inference broken by lru_cache decorator Question: python’s TypeVar inference broken when using lru_cache decorator. For example, after applying mypy the following example, only function with lru_cache causes error like: main.py:14: error: Incompatible types in assignment (expression has type "T", variable has type "int") Found 1 error in 1 file (checked 1 source file) and …

Total answers: 1