Show More
@@ -117,6 +117,13 b' def repr_type(obj):' | |||||
117 | return msg |
|
117 | return msg | |
118 |
|
118 | |||
119 |
|
119 | |||
|
120 | def is_trait(t): | |||
|
121 | """ Returns whether the given value is an instance or subclass of TraitType. | |||
|
122 | """ | |||
|
123 | return (isinstance(t, TraitType) or | |||
|
124 | (isinstance(t, type) and issubclass(t, TraitType))) | |||
|
125 | ||||
|
126 | ||||
120 | def parse_notifier_name(name): |
|
127 | def parse_notifier_name(name): | |
121 | """Convert the name argument to a list of names. |
|
128 | """Convert the name argument to a list of names. | |
122 |
|
129 | |||
@@ -1165,10 +1172,8 b' class Container(Instance):' | |||||
1165 | further keys for extensions to the Trait (e.g. config) |
|
1172 | further keys for extensions to the Trait (e.g. config) | |
1166 |
|
1173 | |||
1167 | """ |
|
1174 | """ | |
1168 | istrait = lambda t: isinstance(t, type) and issubclass(t, TraitType) |
|
|||
1169 |
|
||||
1170 | # allow List([values]): |
|
1175 | # allow List([values]): | |
1171 | if default_value is None and not istrait(trait): |
|
1176 | if default_value is None and not is_trait(trait): | |
1172 | default_value = trait |
|
1177 | default_value = trait | |
1173 | trait = None |
|
1178 | trait = None | |
1174 |
|
1179 | |||
@@ -1179,8 +1184,8 b' class Container(Instance):' | |||||
1179 | else: |
|
1184 | else: | |
1180 | raise TypeError('default value of %s was %s' %(self.__class__.__name__, default_value)) |
|
1185 | raise TypeError('default value of %s was %s' %(self.__class__.__name__, default_value)) | |
1181 |
|
1186 | |||
1182 | if istrait(trait): |
|
1187 | if is_trait(trait): | |
1183 | self._trait = trait() |
|
1188 | self._trait = trait() if isinstance(trait, type) else trait | |
1184 | self._trait.name = 'element' |
|
1189 | self._trait.name = 'element' | |
1185 | elif trait is not None: |
|
1190 | elif trait is not None: | |
1186 | raise TypeError("`trait` must be a Trait or None, got %s"%repr_type(trait)) |
|
1191 | raise TypeError("`trait` must be a Trait or None, got %s"%repr_type(trait)) | |
@@ -1327,10 +1332,8 b' class Tuple(Container):' | |||||
1327 | default_value = metadata.pop('default_value', None) |
|
1332 | default_value = metadata.pop('default_value', None) | |
1328 | allow_none = metadata.pop('allow_none', True) |
|
1333 | allow_none = metadata.pop('allow_none', True) | |
1329 |
|
1334 | |||
1330 | istrait = lambda t: isinstance(t, type) and issubclass(t, TraitType) |
|
|||
1331 |
|
||||
1332 | # allow Tuple((values,)): |
|
1335 | # allow Tuple((values,)): | |
1333 | if len(traits) == 1 and default_value is None and not istrait(traits[0]): |
|
1336 | if len(traits) == 1 and default_value is None and not is_trait(traits[0]): | |
1334 | default_value = traits[0] |
|
1337 | default_value = traits[0] | |
1335 | traits = () |
|
1338 | traits = () | |
1336 |
|
1339 | |||
@@ -1343,7 +1346,7 b' class Tuple(Container):' | |||||
1343 |
|
1346 | |||
1344 | self._traits = [] |
|
1347 | self._traits = [] | |
1345 | for trait in traits: |
|
1348 | for trait in traits: | |
1346 | t = trait() |
|
1349 | t = trait() if isinstance(trait, type) else trait | |
1347 | t.name = 'element' |
|
1350 | t.name = 'element' | |
1348 | self._traits.append(t) |
|
1351 | self._traits.append(t) | |
1349 |
|
1352 |
General Comments 0
You need to be logged in to leave comments.
Login now