From f3f001e14a4aab3afc4a8ee14ad237406273bd53 Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Fri, 6 Nov 2015 12:39:59 -0500 Subject: [PATCH] ENH: Raise on attempt to set a lazyval. --- zipline/utils/memoize.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/zipline/utils/memoize.py b/zipline/utils/memoize.py index 354649bf..ddb24b1d 100644 --- a/zipline/utils/memoize.py +++ b/zipline/utils/memoize.py @@ -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, owner): + raise AttributeError("Can't set read-only attribute.") + def remember_last(f): """