How to fix Python TypeError: lru_cache() got an unexpected keyword argument 'max_size
Problem:
In Python, you’re using code such as
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
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.