diff options
author | hut <hut@lavabit.com> | 2011-10-07 21:32:16 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2011-10-07 21:32:16 +0200 |
commit | c1b42fd54b7670b829866d14221b4ab6cfcb1fba (patch) | |
tree | 02a58f907f22d62a86a8673615e8952b4281e045 /ranger | |
parent | aa717a186e793b1972a0a62b76353c399d4ae1c0 (diff) | |
download | ranger-c1b42fd54b7670b829866d14221b4ab6cfcb1fba.tar.gz |
ext.lazy_property: added doctest
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/ext/lazy_property.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/ranger/ext/lazy_property.py b/ranger/ext/lazy_property.py index 320a1993..734d9616 100644 --- a/ranger/ext/lazy_property.py +++ b/ranger/ext/lazy_property.py @@ -4,12 +4,17 @@ class lazy_property(object): """ A @property-like decorator with lazy evaluation - Example: - class Foo: - @lazy_property - def bar(self): - result = [...] - return result + >>> 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): @@ -23,3 +28,7 @@ class lazy_property(object): result = self._method(obj) obj.__dict__[self.__name__] = result return result + +if __name__ == '__main__': + import doctest + doctest.testmod() |