summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2011-10-07 21:32:16 +0200
committerhut <hut@lavabit.com>2011-10-07 21:32:16 +0200
commitc1b42fd54b7670b829866d14221b4ab6cfcb1fba (patch)
tree02a58f907f22d62a86a8673615e8952b4281e045
parentaa717a186e793b1972a0a62b76353c399d4ae1c0 (diff)
downloadranger-c1b42fd54b7670b829866d14221b4ab6cfcb1fba.tar.gz
ext.lazy_property: added doctest
-rw-r--r--ranger/ext/lazy_property.py21
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()