[IMP] No cause to store self.fget.__name__ to its own attribute when it's only used once
bzr revid: xmo@openerp.com-20140418130629-30vp1veih7jfmnx7
This commit is contained in:
parent
24512edac9
commit
4934579abb
|
@ -34,20 +34,19 @@ class lazy_property(object):
|
|||
"""
|
||||
def __init__(self, fget):
|
||||
self.fget = fget
|
||||
self.name = fget.__name__
|
||||
|
||||
def __get__(self, obj, cls):
|
||||
if obj is None:
|
||||
return self
|
||||
value = self.fget(obj)
|
||||
setattr(obj, self.name, value)
|
||||
setattr(obj, self.fget.__name__, value)
|
||||
return value
|
||||
|
||||
@staticmethod
|
||||
def reset_all(obj):
|
||||
""" Reset all lazy properties on the instance `obj`. """
|
||||
cls = type(obj)
|
||||
obj_dict = obj.__dict__
|
||||
obj_dict = vars(obj)
|
||||
for name in obj_dict.keys():
|
||||
if isinstance(getattr(cls, name, None), lazy_property):
|
||||
obj_dict.pop(name)
|
||||
|
|
Loading…
Reference in New Issue