def testable_memoized_property ( func = None , key_factory = per_instance , * * kwargs ) : getter = memoized_method ( func = func , key_factory = key_factory , * * kwargs ) def setter ( self , val ) : with getter . put ( self ) as putter : putter ( val ) return property ( fget = getter , fset = setter , fdel = lambda self : getter . forget ( self ) )
python cache properties for an immutable object
A variant of memoized_property that allows for setting of properties ( for tests etc ) .
def testable_memoized_property(func=None, key_factory=per_instance, **kwargs):
  """A variant of `memoized_property` that allows for setting of properties (for tests, etc)."""
  getter = memoized_method(func=func, key_factory=key_factory, **kwargs)

  def setter(self, val):
    with getter.put(self) as putter:
      putter(val)

  return property(fget=getter,
                  fset=setter,
                  fdel=lambda self: getter.forget(self))