def useless_decorator(fn): return decorate(UselessDecorator)(fn)
def dirty(self, *args): try: del self._cache[args] except KeyError: pass def __call__(self, *args): try: return self._cache[args] except KeyError: value = self.fn(*args) self._cache[args] = value return value cached = decorate(CacheDecorator) i = 0 @cached def f(a, b): global i i += 1 return a + b + i class CachedMethods(object): @cached def f(self, a, b): global i