From f3f001e14a4aab3afc4a8ee14ad237406273bd53 Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Fri, 6 Nov 2015 12:39:59 -0500 Subject: [PATCH 1/2] 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): """ From 6b49081f54d83573301f9bb7cf0f284ddc1660c2 Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Fri, 6 Nov 2015 13:03:31 -0500 Subject: [PATCH 2/2] MAINT: __set__ takes instance and value. --- zipline/utils/memoize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zipline/utils/memoize.py b/zipline/utils/memoize.py index ddb24b1d..19fe31f6 100644 --- a/zipline/utils/memoize.py +++ b/zipline/utils/memoize.py @@ -50,7 +50,7 @@ class lazyval(object): self._cache[instance] = val = self._get(instance) return val - def __set__(self, instance, owner): + def __set__(self, instance, value): raise AttributeError("Can't set read-only attribute.")