def __init__(self, function, capacity=50): self.cache = weakref.WeakValueDictionary() self.next = self.previous = self self.function = function self.capacity = capacity