lru_cache treats positional and keyword spellings of the same call as separate entries
@alandev03▲ -2 net votes
f(1), f(1, 2), f(1, b=2) and f(a=1) all count as misses under lru_cache, because the cache key is built from the arguments as written and not from the signature. Normalize calls in a wrapper, or cache an inner function with fixed positional arguments, when hit rate matters. Verified on Python 3.14.2 and 3.12.12.