Show More
@@ -117,6 +117,13 b' def repr_type(obj):' | |||
|
117 | 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 | 127 | def parse_notifier_name(name): |
|
121 | 128 | """Convert the name argument to a list of names. |
|
122 | 129 | |
@@ -1165,10 +1172,8 b' class Container(Instance):' | |||
|
1165 | 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 | 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 | 1177 | default_value = trait |
|
1173 | 1178 | trait = None |
|
1174 | 1179 | |
@@ -1179,8 +1184,8 b' class Container(Instance):' | |||
|
1179 | 1184 | else: |
|
1180 | 1185 | raise TypeError('default value of %s was %s' %(self.__class__.__name__, default_value)) |
|
1181 | 1186 | |
|
1182 | if istrait(trait): | |
|
1183 | self._trait = trait() | |
|
1187 | if is_trait(trait): | |
|
1188 | self._trait = trait() if isinstance(trait, type) else trait | |
|
1184 | 1189 | self._trait.name = 'element' |
|
1185 | 1190 | elif trait is not None: |
|
1186 | 1191 | raise TypeError("`trait` must be a Trait or None, got %s"%repr_type(trait)) |
@@ -1327,10 +1332,8 b' class Tuple(Container):' | |||
|
1327 | 1332 | default_value = metadata.pop('default_value', None) |
|
1328 | 1333 | allow_none = metadata.pop('allow_none', True) |
|
1329 | 1334 | |
|
1330 | istrait = lambda t: isinstance(t, type) and issubclass(t, TraitType) | |
|
1331 | ||
|
1332 | 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 | 1337 | default_value = traits[0] |
|
1335 | 1338 | traits = () |
|
1336 | 1339 | |
@@ -1343,7 +1346,7 b' class Tuple(Container):' | |||
|
1343 | 1346 | |
|
1344 | 1347 | self._traits = [] |
|
1345 | 1348 | for trait in traits: |
|
1346 | t = trait() | |
|
1349 | t = trait() if isinstance(trait, type) else trait | |
|
1347 | 1350 | t.name = 'element' |
|
1348 | 1351 | self._traits.append(t) |
|
1349 | 1352 |
General Comments 0
You need to be logged in to leave comments.
Login now