mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-27 18:58:48 +08:00
Merge pull request #822 from quantopian/cant-set-lazy
ENH: Raise on attempt to set a lazyval.
This commit is contained in:
@@ -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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user