From 124e38751ca15137b1d896e3ab0d9bc646e945f8 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Tue, 28 May 2013 23:34:52 -0500 Subject: [PATCH] Fix `RequiredAttrs` definition. The example in python's descriptor tutorial creates a singleton so multiple, instances share the same attribute. This update fixes the issue based on [1]. [1] http://stackoverflow.com/questions/8718052/where-does-a-python-descriptors-state-go --- skimage/viewer/utils/core.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/skimage/viewer/utils/core.py b/skimage/viewer/utils/core.py index 0dcd4176..7ea28fab 100644 --- a/skimage/viewer/utils/core.py +++ b/skimage/viewer/utils/core.py @@ -42,17 +42,22 @@ def start_qtapp(): class RequiredAttr(object): """A class attribute that must be set before use.""" - def __init__(self, msg): + instances = dict() + + def __init__(self, msg='Required attribute not set', init_val=None): + self.instances[self, None] = init_val self.msg = msg - self.val = None def __get__(self, obj, objtype): - if self.val is None: + value = self.instances[self, obj] + if value is None: + # Should raise an error but that causes issues with the buildbot. warnings.warn(self.msg) - return self.val + self.__set__(obj, self.init_val) + return value - def __set__(self, obj, val): - self.val = val + def __set__(self, obj, value): + self.instances[self, obj] = value class LinearColormap(LinearSegmentedColormap):