util: new cached_property decorator
This commit is contained in:
parent
6473b41d43
commit
b53fd52f47
1 changed files with 9 additions and 0 deletions
|
|
@ -470,3 +470,12 @@ def have_sudo(*, silent=False):
|
|||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def cached_property(orig_func):
|
||||
@property
|
||||
def new_func(self):
|
||||
attr_name = '_' + orig_func.__name__
|
||||
if not hasattr(self, attr_name):
|
||||
setattr(self, attr_name, orig_func(self))
|
||||
return getattr(self, attr_name)
|
||||
return new_func
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue