Show More
@@ -356,7 +356,7 b' class TraitType(object):' | |||||
356 | """Create a new instance of the default value.""" |
|
356 | """Create a new instance of the default value.""" | |
357 | return self.default_value |
|
357 | return self.default_value | |
358 |
|
358 | |||
359 |
def decorate(self |
|
359 | def decorate(self): | |
360 | pass |
|
360 | pass | |
361 |
|
361 | |||
362 | def static_init(self, obj): |
|
362 | def static_init(self, obj): | |
@@ -550,7 +550,7 b' class HasTraits(py3compat.with_metaclass(MetaHasTraits, object)):' | |||||
550 | pass |
|
550 | pass | |
551 | else: |
|
551 | else: | |
552 | if isinstance(value, TraitType): |
|
552 | if isinstance(value, TraitType): | |
553 |
value.decorate( |
|
553 | value.decorate() | |
554 | if key not in kw: |
|
554 | if key not in kw: | |
555 | value.set_default_value(inst) |
|
555 | value.set_default_value(inst) | |
556 |
|
556 | |||
@@ -845,7 +845,7 b' class Type(ClassBasedTraitType):' | |||||
845 | value = self._resolve_string(value) |
|
845 | value = self._resolve_string(value) | |
846 | except ImportError: |
|
846 | except ImportError: | |
847 | raise TraitError("The '%s' trait of %s instance must be a type, but " |
|
847 | raise TraitError("The '%s' trait of %s instance must be a type, but " | |
848 | "%r could not be imported" % (self.name, obj, value)) |
|
848 | "%r could not be imported" % (self.name, obj, value)) | |
849 | try: |
|
849 | try: | |
850 | if issubclass(value, self.klass): |
|
850 | if issubclass(value, self.klass): | |
851 | return value |
|
851 | return value | |
@@ -865,9 +865,9 b' class Type(ClassBasedTraitType):' | |||||
865 | return result + ' or None' |
|
865 | return result + ' or None' | |
866 | return result |
|
866 | return result | |
867 |
|
867 | |||
868 |
def decorate(self |
|
868 | def decorate(self): | |
869 | self._resolve_classes() |
|
869 | self._resolve_classes() | |
870 |
super(Type, self).decorate( |
|
870 | super(Type, self).decorate() | |
871 |
|
871 | |||
872 | def _resolve_classes(self): |
|
872 | def _resolve_classes(self): | |
873 | if isinstance(self.klass, py3compat.string_types): |
|
873 | if isinstance(self.klass, py3compat.string_types): | |
@@ -974,9 +974,9 b' class Instance(ClassBasedTraitType):' | |||||
974 |
|
974 | |||
975 | return result |
|
975 | return result | |
976 |
|
976 | |||
977 |
def decorate(self |
|
977 | def decorate(self): | |
978 | self._resolve_classes() |
|
978 | self._resolve_classes() | |
979 |
super(Instance, self).decorate( |
|
979 | super(Instance, self).decorate() | |
980 |
|
980 | |||
981 | def _resolve_classes(self): |
|
981 | def _resolve_classes(self): | |
982 | if isinstance(self.klass, py3compat.string_types): |
|
982 | if isinstance(self.klass, py3compat.string_types): | |
@@ -1071,13 +1071,12 b' class Union(TraitType):' | |||||
1071 | self.default_value = self.trait_types[0].get_default_value() |
|
1071 | self.default_value = self.trait_types[0].get_default_value() | |
1072 | super(Union, self).__init__(**metadata) |
|
1072 | super(Union, self).__init__(**metadata) | |
1073 |
|
1073 | |||
1074 |
def decorate(self |
|
1074 | def decorate(self): | |
1075 | for trait_type in self.trait_types: |
|
1075 | for trait_type in self.trait_types: | |
1076 | trait_type.name = self.name |
|
1076 | trait_type.name = self.name | |
1077 | trait_type.this_class = self.this_class |
|
1077 | trait_type.this_class = self.this_class | |
1078 | if hasattr(trait_type, '_resolve_classes'): |
|
1078 | trait_type.decorate() | |
1079 | trait_type._resolve_classes() |
|
1079 | super(Union, self).decorate() | |
1080 | super(Union, self).decorate(obj) |
|
|||
1081 |
|
1080 | |||
1082 | def validate(self, obj, value): |
|
1081 | def validate(self, obj, value): | |
1083 | for trait_type in self.trait_types: |
|
1082 | for trait_type in self.trait_types: | |
@@ -1458,12 +1457,11 b' class Container(Instance):' | |||||
1458 | validated.append(v) |
|
1457 | validated.append(v) | |
1459 | return self.klass(validated) |
|
1458 | return self.klass(validated) | |
1460 |
|
1459 | |||
1461 |
def decorate(self |
|
1460 | def decorate(self): | |
1462 | if isinstance(self._trait, TraitType): |
|
1461 | if isinstance(self._trait, TraitType): | |
1463 | self._trait.this_class = self.this_class |
|
1462 | self._trait.this_class = self.this_class | |
1464 | if hasattr(self._trait, '_resolve_classes'): |
|
1463 | self._trait.decorate() | |
1465 | self._trait._resolve_classes() |
|
1464 | super(Container, self).decorate() | |
1466 | super(Container, self).decorate(obj) |
|
|||
1467 |
|
1465 | |||
1468 |
|
1466 | |||
1469 | class List(Container): |
|
1467 | class List(Container): | |
@@ -1525,14 +1523,11 b' class List(Container):' | |||||
1525 | self.length_error(obj, value) |
|
1523 | self.length_error(obj, value) | |
1526 |
|
1524 | |||
1527 | return super(List, self).validate_elements(obj, value) |
|
1525 | return super(List, self).validate_elements(obj, value) | |
1528 |
|
1526 | |||
1529 | def validate(self, obj, value): |
|
1527 | def validate(self, obj, value): | |
1530 | value = super(List, self).validate(obj, value) |
|
1528 | value = super(List, self).validate(obj, value) | |
1531 |
|
||||
1532 | value = self.validate_elements(obj, value) |
|
1529 | value = self.validate_elements(obj, value) | |
1533 |
|
||||
1534 | return value |
|
1530 | return value | |
1535 |
|
||||
1536 |
|
1531 | |||
1537 |
|
1532 | |||
1538 | class Set(List): |
|
1533 | class Set(List): | |
@@ -1540,6 +1535,7 b' class Set(List):' | |||||
1540 | klass = set |
|
1535 | klass = set | |
1541 | _cast_types = (tuple, list) |
|
1536 | _cast_types = (tuple, list) | |
1542 |
|
1537 | |||
|
1538 | ||||
1543 | class Tuple(Container): |
|
1539 | class Tuple(Container): | |
1544 | """An instance of a Python tuple.""" |
|
1540 | """An instance of a Python tuple.""" | |
1545 | klass = tuple |
|
1541 | klass = tuple | |
@@ -1629,13 +1625,12 b' class Tuple(Container):' | |||||
1629 | validated.append(v) |
|
1625 | validated.append(v) | |
1630 | return tuple(validated) |
|
1626 | return tuple(validated) | |
1631 |
|
1627 | |||
1632 |
def decorate(self |
|
1628 | def decorate(self): | |
1633 | for trait in self._traits: |
|
1629 | for trait in self._traits: | |
1634 | if isinstance(trait, TraitType): |
|
1630 | if isinstance(trait, TraitType): | |
1635 | trait.this_class = self.this_class |
|
1631 | trait.this_class = self.this_class | |
1636 | if hasattr(trait, '_resolve_classes'): |
|
1632 | trait.decorate() | |
1637 | trait._resolve_classes() |
|
1633 | super(Container, self).decorate() | |
1638 | super(Container, self).decorate(obj) |
|
|||
1639 |
|
1634 | |||
1640 |
|
1635 | |||
1641 | class Dict(Instance): |
|
1636 | class Dict(Instance): |
General Comments 0
You need to be logged in to leave comments.
Login now