summaryrefslogtreecommitdiff
path: root/coverage/misc.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/misc.py')
-rw-r--r--coverage/misc.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/coverage/misc.py b/coverage/misc.py
index 8e4b3362..329a8417 100644
--- a/coverage/misc.py
+++ b/coverage/misc.py
@@ -45,6 +45,20 @@ def format_lines(statements, lines):
return ret
+def expensive(fn):
+ """A decorator to cache the result of an expensive operation.
+
+ Only applies to methods with no arguments.
+
+ """
+ attr = "_cache_" + fn.__name__
+ def _wrapped(self):
+ if not hasattr(self, attr):
+ setattr(self, attr, fn(self))
+ return getattr(self, attr)
+ return _wrapped
+
+
class CoverageException(Exception):
"""An exception specific to Coverage."""
pass