Created
April 22, 2018 08:59
-
-
Save Swalloow/16513e81d0e59884e93d6b2dfe3b3429 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
def lazy_property(function): | |
attribute = '_cache_' + function.__name__ | |
@property | |
@functools.wraps(function) | |
def decorator(self): | |
if not hasattr(self, attribute): | |
setattr(self, attribute, function(self)) | |
return getattr(self, attribute) | |
return decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment