Using functools.lru_cache on functions with constant but non-hashable objects
问题 Is it possible to use functools.lru_cache for caching a partial function created by functools.partial ? My problem is a function that takes hashable parameters and contant, non-hashable objects such as NumPy arrays. Consider this toy example: import numpy as np from functools import lru_cache, partial def foo(key, array): print('%s:' % key, array) a = np.array([1,2,3]) Since NumPy arrays are not hashable, this will not work: @lru_cache(maxsize=None) def foo(key, array): print('%s:' % key,