Show More
@@ -1001,6 +1001,19 b' class TestInstanceList(TraitTestBase):' | |||||
1001 | _good_values = [[Foo(), Foo(), None], None] |
|
1001 | _good_values = [[Foo(), Foo(), None], None] | |
1002 | _bad_values = [['1', 2,], '1', [Foo]] |
|
1002 | _bad_values = [['1', 2,], '1', [Foo]] | |
1003 |
|
1003 | |||
|
1004 | class UnionListTrait(HasTraits): | |||
|
1005 | ||||
|
1006 | value = List(Int() | Bool()) | |||
|
1007 | ||||
|
1008 | class TestUnionListTrait(HasTraits): | |||
|
1009 | ||||
|
1010 | obj = UnionListTrait() | |||
|
1011 | ||||
|
1012 | _default_value = [] | |||
|
1013 | _good_values = [[True, 1], [False, True]] | |||
|
1014 | _bad_values = [[1, 'True'], False] | |||
|
1015 | ||||
|
1016 | ||||
1004 | class LenListTrait(HasTraits): |
|
1017 | class LenListTrait(HasTraits): | |
1005 |
|
1018 | |||
1006 | value = List(Int, [0], minlen=1, maxlen=2) |
|
1019 | value = List(Int, [0], minlen=1, maxlen=2) |
@@ -1071,12 +1071,15 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 instance_init(self, obj): |
|
1074 | def _resolve_classes(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 | if hasattr(trait_type, '_resolve_classes'): | |
1079 | trait_type._resolve_classes() |
|
1079 | trait_type._resolve_classes() | |
|
1080 | ||||
|
1081 | def instance_init(self, obj): | |||
|
1082 | self._resolve_classes() | |||
1080 | super(Union, self).instance_init(obj) |
|
1083 | super(Union, self).instance_init(obj) | |
1081 |
|
1084 | |||
1082 | def validate(self, obj, value): |
|
1085 | def validate(self, obj, value): |
General Comments 0
You need to be logged in to leave comments.
Login now