diff options
Diffstat (limited to 'ranger/ext/lazy_property.py')
-rw-r--r-- | ranger/ext/lazy_property.py | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/ranger/ext/lazy_property.py b/ranger/ext/lazy_property.py index 734d9616..60d3c802 100644 --- a/ranger/ext/lazy_property.py +++ b/ranger/ext/lazy_property.py @@ -1,34 +1,34 @@ # From http://blog.pythonisito.com/2008/08/lazy-descriptors.html class lazy_property(object): - """ - A @property-like decorator with lazy evaluation + """ + A @property-like decorator with lazy evaluation - >>> class Foo: - ... @lazy_property - ... def answer(self): - ... print("calculating answer...") - ... return 2*3*7 - >>> foo = Foo() - >>> foo.answer - calculating answer... - 42 - >>> foo.answer - 42 - """ + >>> class Foo: + ... @lazy_property + ... def answer(self): + ... print("calculating answer...") + ... return 2*3*7 + >>> foo = Foo() + >>> foo.answer + calculating answer... + 42 + >>> foo.answer + 42 + """ - def __init__(self, method): - self._method = method - self.__name__ = method.__name__ - self.__doc__ = method.__doc__ + def __init__(self, method): + self._method = method + self.__name__ = method.__name__ + self.__doc__ = method.__doc__ - def __get__(self, obj, cls=None): - if obj is None: # to fix issues with pydoc - return None - result = self._method(obj) - obj.__dict__[self.__name__] = result - return result + def __get__(self, obj, cls=None): + if obj is None: # to fix issues with pydoc + return None + result = self._method(obj) + obj.__dict__[self.__name__] = result + return result if __name__ == '__main__': - import doctest - doctest.testmod() + import doctest + doctest.testmod() |