forked from rDrama/rDrama
1
0
Fork 0
rDrama/files/helpers/lazy.py

19 lines
399 B
Python
Raw Normal View History

2021-07-21 01:12:26 +00:00
# Prevents certain properties from having to be recomputed each time they
# are referenced
def lazy(f):
def wrapper(*args, **kwargs):
o = args[0]
2021-09-19 12:46:30 +00:00
if "_lazy" not in o.__dict__: o.__dict__["_lazy"] = {}
2021-07-21 01:12:26 +00:00
2021-09-19 12:46:30 +00:00
if f.__name__ not in o.__dict__["_lazy"]: o.__dict__["_lazy"][f.__name__] = f(*args, **kwargs)
2021-07-21 01:12:26 +00:00
return o.__dict__["_lazy"][f.__name__]
wrapper.__name__ = f.__name__
return wrapper