Merge pull request #822 from quantopian/cant-set-lazy

ENH: Raise on attempt to set a lazyval.
This commit is contained in:
Scott Sanderson
2015-11-06 13:20:34 -05:00
+9
View File
@@ -30,6 +30,12 @@ class lazyval(object):
('val', 1)
>>> c.val, c.count
('val', 1)
>>> c.val = 'not_val'
Traceback (most recent call last):
...
AttributeError: Can't set read-only attribute.
>>> c.val
'val'
"""
def __init__(self, get):
self._get = get
@@ -44,6 +50,9 @@ class lazyval(object):
self._cache[instance] = val = self._get(instance)
return val
def __set__(self, instance, value):
raise AttributeError("Can't set read-only attribute.")
def remember_last(f):
"""