Exemplo n.º 1
0
def useless_decorator(fn):
    return decorate(UselessDecorator)(fn)
Exemplo n.º 2
0
    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