How to fix Python TypeError: lru_cache() got an unexpected keyword argument 'max_size
Problem:
In Python, you’re using code such as
lru_cache_example.py
from functools import lru_cache
@lru_cache(max_size=128)
def myfunc(arg: str):
# ...
return arg + "x"but you see an error message such as
example.txt
Traceback (most recent call last):
File "/dev/shm/test.py", line 3, in <module>
@lru_cache(max_size=128)
TypeError: lru_cache() got an unexpected keyword argument 'max_size'Solution
You’ve mis-spelled the argument to @lru_cache: You wrote max_size with underscore whereas it actually is maxsize without underscore.
Check out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow