You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python implementation of functools.lru_cache does not check that argument is callable #144030
The C implementation of functools.lru_cache checks whether its argument is callable and raises an exception if not. The Python version does not do that:
importsyssys.modules['_functools'] =Noneimportfunctoolsfunctools.lru_cache()(1) # does not raise
without blocking the import of _functools you get:
Traceback (most recent call last):
File "/home/cfbolz/projects/cpython/functoolserror.py", line 5, in <module>
functools.lru_cache()(1)
~~~~~~~~~~~~~~~~~~~~~^^^
File "/home/cfbolz/projects/cpython/Lib/functools.py", line 598, in decorating_function
wrapper = _lru_cache_wrapper(user_function, maxsize, typed, _CacheInfo)
TypeError: the first argument must be callable
I think this should simply be fixed in the Python implementation and will prepare a patch.
Activity
cfbolz commentedon Jan 19, 2026
(bug found by @zahinwahab via fuzzing and reported first here: pypy/pypy#5369 )
gh-144030: Add check that argument is callable to Python version of f…
vstinner commentedon Jan 21, 2026
Merged, thanks for the fix @cfbolz.
pythongh-144030: Add check that argument is callable to Python versio…