summary refs log tree commit diff stats
diff options
context:
space:
mode:
-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()
11' href='#n111'>111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157