proxy pattern duck typing allows us to create such proxy by copying the object interface and then using the proxy class instead of the original class import time class rawcalculator(object)def fib(selfn)if return return self fib( self fib( def memoize(fn)__cache {def memoized(*args)key (fn __name__argsif key in __cachereturn __cache[key__cache[keyfn(*argsreturn __cache[keyreturn memoized class calculatorproxy(object)def __init__(selftarget)self target target fib getattr(self target'fib'setattr(self target'fib'memoize(fib)def __getattr__(selfname)return getattr(self targetname