Why does functools.lru_cache not cache __call__ while working on normal methods
问题 I have been trying to make functools.lru_cache instance specific as described in this answer, but their solution fails when used on the __call__ method. class test: def __init__(self): self.method = lru_cache()(self.method) self.__call__ = lru_cache()(self.__call__) def method(self, x): print('method', end=' ') return x def __call__(self, x): print('__call__', end=' ') return x b = test() # b.method is cached as expected print(b.method(1)) # method 1 print(b.method(1)) # 1 # __call__ is