<s> '''<STR_LIT>''' <EOL> from python_toolbox import decorator_tools <EOL> from python_toolbox import misc_tools <EOL> class CachedProperty ( misc_tools . OwnNameDiscoveringDescriptor ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , getter_or_value , doc = None , name = None , <EOL> force_value_not_getter = False ) : <EOL> '''<STR_LIT>''' <EOL> misc_tools . OwnNameDiscoveringDescriptor . __init__ ( self , name = name ) <EOL> if callable ( getter_or_value ) and not force_value_not_getter : <EOL> self . getter = getter_or_value <EOL> else : <EOL> self . getter = lambda thing : getter_or_value <EOL> self . __doc__ = doc or getattr ( self . getter , '<STR_LIT>' , None ) <EOL> def __get__ ( self , thing , our_type = None ) : <EOL> if thing is None : <EOL> return self <EOL> value = self . getter ( thing ) <EOL> setattr ( thing , self . get_our_name ( thing , our_type = our_type ) , value ) <EOL> return value <EOL> def __call__ ( self , method_function ) : <EOL> '''<STR_LIT>''' <EOL> def inner ( same_method_function , self_obj , * args , ** kwargs ) : <EOL> with getattr ( self_obj , self . get_our_name ( self_obj ) ) : <EOL> return method_function ( self_obj , * args , ** kwargs ) <EOL> return decorator_tools . decorator ( inner , method_function ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( type ( self ) . __name__ , self . our_name or self . getter ) </s>
