def memoized_instancemethod(fn):
 def oneshot(self, *args, **kw):
  result = fn(self, *args, **kw)
  memo = (lambda *a, **kw: result)
  memo.__name__ = fn.__name__
  memo.__doc__ = fn.__doc__
  self.__dict__[fn.__name__] = memo
  return result
 return update_wrapper(oneshot, fn)

def memoized_instancemethod ( fn ) : def oneshot ( self , * args , ** kw ) : result = fn ( self , * args , ** kw ) memo = ( lambda * a , ** kw : result ) memo . __name__ = fn . __name__ memo . __doc__ = fn . __doc__ self . __dict__ [ fn . __name__ ] = memo return result return update_wrapper ( oneshot , fn )
decorate a method memoize its return value .