Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: AN Long <aisk@users.noreply.github.com>
return decorating_function
def _lru_cache_wrapper(user_function, maxsize, typed, _CacheInfo):
+ if not callable(user_function):
+ raise TypeError("the first argument must be callable")
+
# Constants shared by all lru cache instances:
sentinel = object() # unique object used to signal cache misses
make_key = _make_key # build a key from the function arguments
with self.assertRaises(RecursionError):
fib(support.exceeds_recursion_limit())
+ def test_lru_checks_arg_is_callable(self):
+ with self.assertRaisesRegex(
+ TypeError,
+ "the first argument must be callable",
+ ):
+ self.module.lru_cache(1)('hello')
+
@py_functools.lru_cache()
def py_cached_func(x, y):
--- /dev/null
+The Python implementation of :func:`functools.lru_cache` differed from the
+default C implementation in that it did not check that its argument is
+callable. This discrepancy is now fixed and both raise a :exc:`TypeError`.