Show More
@@ -360,39 +360,24 b' class TraitType(object):' | |||||
360 | pass |
|
360 | pass | |
361 |
|
361 | |||
362 | def static_init(self, obj): |
|
362 | def static_init(self, obj): | |
363 | # We didn't find one. Do static initialization. |
|
|||
364 | value = self.get_default_value() |
|
363 | value = self.get_default_value() | |
365 | value = self._validate(obj, value) |
|
364 | value = self._validate(obj, value) | |
366 | obj._trait_values[self.name] = value |
|
365 | obj._trait_values[self.name] = value | |
367 | return value |
|
366 | return value | |
368 |
|
367 | |||
369 | def instance_init(self, obj): |
|
|||
370 | """This is called by :meth:`HasTraits.__new__` to finish init'ing. |
|
|||
371 |
|
||||
372 | Some stages of initialization must be delayed until the parent |
|
|||
373 | :class:`HasTraits` instance has been created. This method is |
|
|||
374 | called in :meth:`HasTraits.__new__` after the instance has been |
|
|||
375 | created. |
|
|||
376 |
|
||||
377 | This method trigger the creation and validation of default values |
|
|||
378 | and also things like the resolution of str given class names in |
|
|||
379 | :class:`Type` and :class`Instance`. |
|
|||
380 |
|
||||
381 | Parameters |
|
|||
382 | ---------- |
|
|||
383 | obj : :class:`HasTraits` instance |
|
|||
384 | The parent :class:`HasTraits` instance that has just been |
|
|||
385 | created. |
|
|||
386 | """ |
|
|||
387 | self.set_default_value(obj) |
|
|||
388 |
|
||||
389 | def set_default_value(self, obj): |
|
368 | def set_default_value(self, obj): | |
390 | """Set the default value on a per instance basis. |
|
369 | """Set the default value on a per instance basis. | |
391 |
|
370 | |||
392 |
This method is called by :meth:` |
|
371 | This method is called by :meth:`HasTraits.__new__` to create and | |
393 | validate the default value. The creation and validation of |
|
372 | validate the default value. The creation and validation of | |
394 | default values must be delayed until the parent :class:`HasTraits` |
|
373 | default values must be delayed until the parent :class:`HasTraits` | |
395 | class has been instantiated. |
|
374 | class has been instantiated. | |
|
375 | ||||
|
376 | Parameters | |||
|
377 | ---------- | |||
|
378 | obj : :class:`HasTraits` instance | |||
|
379 | The parent :class:`HasTraits` instance that has just been | |||
|
380 | created. | |||
396 | """ |
|
381 | """ | |
397 | # Check for a deferred initializer defined in the same class as the |
|
382 | # Check for a deferred initializer defined in the same class as the | |
398 | # trait declaration or above. |
|
383 | # trait declaration or above. | |
@@ -402,6 +387,7 b' class TraitType(object):' | |||||
402 | if meth_name in cls.__dict__: |
|
387 | if meth_name in cls.__dict__: | |
403 | break |
|
388 | break | |
404 | else: |
|
389 | else: | |
|
390 | # We didn't find one. Do static initialization. | |||
405 | self.static_init(obj) |
|
391 | self.static_init(obj) | |
406 | return |
|
392 | return | |
407 | # Complete the dynamic initialization. |
|
393 | # Complete the dynamic initialization. | |
@@ -566,7 +552,7 b' class HasTraits(py3compat.with_metaclass(MetaHasTraits, object)):' | |||||
566 | if isinstance(value, TraitType): |
|
552 | if isinstance(value, TraitType): | |
567 | value.decorate(inst) |
|
553 | value.decorate(inst) | |
568 | if key not in kw: |
|
554 | if key not in kw: | |
569 |
value. |
|
555 | value.set_default_value(inst) | |
570 |
|
556 | |||
571 | return inst |
|
557 | return inst | |
572 |
|
558 |
General Comments 0
You need to be logged in to leave comments.
Login now