Show More
@@ -142,15 +142,27 b' class TestTraitType(TestCase):' | |||
|
142 | 142 | |
|
143 | 143 | a = A() |
|
144 | 144 | self.assertEquals(a._trait_values, {}) |
|
145 | self.assertEquals(a._trait_dyn_inits.keys(), ['x']) | |
|
145 | 146 | self.assertEquals(a.x, 11) |
|
146 | 147 | self.assertEquals(a._trait_values, {'x': 11}) |
|
147 | 148 | b = B() |
|
148 | 149 | self.assertEquals(b._trait_values, {'x': 20}) |
|
150 | self.assertEquals(a._trait_dyn_inits.keys(), ['x']) | |
|
149 | 151 | self.assertEquals(b.x, 20) |
|
150 | 152 | c = C() |
|
151 | 153 | self.assertEquals(c._trait_values, {}) |
|
154 | self.assertEquals(a._trait_dyn_inits.keys(), ['x']) | |
|
152 | 155 | self.assertEquals(c.x, 21) |
|
153 | 156 | self.assertEquals(c._trait_values, {'x': 21}) |
|
157 | # Ensure that the base class remains unmolested when the _default | |
|
158 | # initializer gets overridden in a subclass. | |
|
159 | a = A() | |
|
160 | c = C() | |
|
161 | self.assertEquals(a._trait_values, {}) | |
|
162 | self.assertEquals(a._trait_dyn_inits.keys(), ['x']) | |
|
163 | self.assertEquals(a.x, 11) | |
|
164 | self.assertEquals(a._trait_values, {'x': 11}) | |
|
165 | ||
|
154 | 166 | |
|
155 | 167 | |
|
156 | 168 | class TestHasTraitsMeta(TestCase): |
@@ -262,7 +262,7 b' class TraitType(object):' | |||
|
262 | 262 | obj._trait_values[self.name] = newdv |
|
263 | 263 | return |
|
264 | 264 | # Complete the dynamic initialization. |
|
265 |
self. |
|
|
265 | obj._trait_dyn_inits[self.name] = cls.__dict__[meth_name] | |
|
266 | 266 | |
|
267 | 267 | def __get__(self, obj, cls=None): |
|
268 | 268 | """Get the value of the trait by self.name for the instance. |
@@ -279,8 +279,8 b' class TraitType(object):' | |||
|
279 | 279 | value = obj._trait_values[self.name] |
|
280 | 280 | except KeyError: |
|
281 | 281 | # Check for a dynamic initializer. |
|
282 |
if |
|
|
283 |
value = self. |
|
|
282 | if self.name in obj._trait_dyn_inits: | |
|
283 | value = obj._trait_dyn_inits[self.name](obj) | |
|
284 | 284 | # FIXME: Do we really validate here? |
|
285 | 285 | value = self._validate(obj, value) |
|
286 | 286 | obj._trait_values[self.name] = value |
@@ -318,11 +318,6 b' class TraitType(object):' | |||
|
318 | 318 | else: |
|
319 | 319 | return value |
|
320 | 320 | |
|
321 | def set_dynamic_initializer(self, method): | |
|
322 | """ Set the dynamic initializer method, if any. | |
|
323 | """ | |
|
324 | self.dynamic_initializer = method | |
|
325 | ||
|
326 | 321 | def info(self): |
|
327 | 322 | return self.info_text |
|
328 | 323 | |
@@ -399,6 +394,7 b' class HasTraits(object):' | |||
|
399 | 394 | inst = new_meth(cls, **kw) |
|
400 | 395 | inst._trait_values = {} |
|
401 | 396 | inst._trait_notifiers = {} |
|
397 | inst._trait_dyn_inits = {} | |
|
402 | 398 | # Here we tell all the TraitType instances to set their default |
|
403 | 399 | # values on the instance. |
|
404 | 400 | for key in dir(cls): |
General Comments 0
You need to be logged in to leave comments.
Login now