Source

options / testprop.py

Diff from to

File testprop.py

     # nb must set property in __class__ (here, E) not in instance (e)
     
 class Setter(object):
-    def __init__(self, initial, updater):
+    def __init__(self, initial, setter=None, getter=None):
         self.initial = initial
-        self.updater = updater
+        self.setter = setter
+        self.getter = getter
     
 class Stuffer(object):
     def __init__(self, **kwargs):
         for k,v in kwargs.items():
             if isinstance(v, Setter):
                 self.s[k] = v.initial
-                self.magic[k] = v.updater
+                self.magic[k] = v.setter
             else:
                 self.s[k] = v
 
         if key in self.__dict__:
             return self.__dict__[key]
         # handle special attributes
+        elif key in self.magic:
+            getter = self.magic[key]
+            return getter(self.s[key]) if getter else self.s[key]   
         else:
             return self.s[key]
     
         for k,v in kwargs.items():
             if isinstance(v, Setter):
                 self[k] = v.initial
-                self._magic[k] = v.updater
+                self._magic[k] = v
             else:
                 self[k] = v
+                
+    def __getattr__(self, key):
+        # handle normal object attributes
+        if key == '_magic' or key in self.__dict__:
+            return self.__dict__[key]  # BREAKS HERE
+        # handle special attributes
+        elif key in self._magic:
+            getter = self._magic[key].getter
+            return getter(self[key]) if getter else self[key]   
+        else:
+            return self[key]
     
     def __setattr__(self, key, value):
         # handle normal object attributes
         if key == '_magic' or key in self.__dict__:
             stuf.__setattr__(self, key, value)
         elif key in self._magic:
-            value = self._magic[key](value)
+            value = self._magic[key].setter(value)
             self[key] = value
         else:
             self[key] = value