diff options
Diffstat (limited to 'lib/spack/llnl/util/lang.py')
-rw-r--r-- | lib/spack/llnl/util/lang.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/spack/llnl/util/lang.py b/lib/spack/llnl/util/lang.py index b3236fa0e7..463310b7a2 100644 --- a/lib/spack/llnl/util/lang.py +++ b/lib/spack/llnl/util/lang.py @@ -1072,3 +1072,15 @@ class GroupedExceptionForwarder(object): # Suppress any exception from being re-raised: # https://docs.python.org/3/reference/datamodel.html#object.__exit__. return True + + +class classproperty(object): + """Non-data descriptor to evaluate a class-level property. The function that performs + the evaluation is injected at creation time and take an instance (could be None) and + an owner (i.e. the class that originated the instance) + """ + def __init__(self, callback): + self.callback = callback + + def __get__(self, instance, owner): + return self.callback(owner) |