Source code for allensdk.core.lazy_property.lazy_property_mixin
from .lazy_property import LazyProperty
[docs]class LazyPropertyMixin(object):
@property
def LazyProperty(self):
return LazyProperty
def __getattribute__(self, name):
lazy_class = super(LazyPropertyMixin, self).__getattribute__('LazyProperty')
curr_attr = super(LazyPropertyMixin, self).__getattribute__(name)
if isinstance(curr_attr, lazy_class):
return curr_attr.__get__(curr_attr)
else:
return super(LazyPropertyMixin, self).__getattribute__(name)
def __setattr__(self, name, value):
if not hasattr(self, name):
super(LazyPropertyMixin, self).__setattr__(name, value)
else:
curr_attr = super(LazyPropertyMixin, self).__getattribute__(name)
lazy_class = super(LazyPropertyMixin, self).__getattribute__('LazyProperty')
if isinstance(curr_attr, lazy_class):
curr_attr.__set__(curr_attr, value)
else:
super(LazyPropertyMixin, self).__setattr__(name, value)