Show More
@@ -1326,11 +1326,11 class TestEventful(TestCase): | |||
|
1326 | 1326 | ### |
|
1327 | 1327 | class ForwardDeclaredInstanceTrait(HasTraits): |
|
1328 | 1328 | |
|
1329 |
value = ForwardDeclaredInstance( |
|
|
1329 | value = ForwardDeclaredInstance('ForwardDeclaredBar') | |
|
1330 | 1330 | |
|
1331 | 1331 | class ForwardDeclaredTypeTrait(HasTraits): |
|
1332 | 1332 | |
|
1333 |
value = ForwardDeclaredType( |
|
|
1333 | value = ForwardDeclaredType('ForwardDeclaredBar') | |
|
1334 | 1334 | |
|
1335 | 1335 | class ForwardDeclaredInstanceListTrait(HasTraits): |
|
1336 | 1336 |
@@ -750,6 +750,12 class HasTraits(py3compat.with_metaclass(MetaHasTraits, object)): | |||
|
750 | 750 | class ClassBasedTraitType(TraitType): |
|
751 | 751 | """A trait with error reporting for Type, Instance and This.""" |
|
752 | 752 | |
|
753 | def _resolve_string(self, string): | |
|
754 | """ | |
|
755 | Resolve a string supplied for a type into an actual object. | |
|
756 | """ | |
|
757 | return import_item(string) | |
|
758 | ||
|
753 | 759 | def error(self, obj, value): |
|
754 | 760 | kind = type(value) |
|
755 | 761 | if (not py3compat.PY3) and kind is InstanceType: |
@@ -842,9 +848,9 class Type(ClassBasedTraitType): | |||
|
842 | 848 | |
|
843 | 849 | def _resolve_classes(self): |
|
844 | 850 | if isinstance(self.klass, py3compat.string_types): |
|
845 |
self.klass = |
|
|
851 | self.klass = self._resolve_string(self.klass) | |
|
846 | 852 | if isinstance(self.default_value, py3compat.string_types): |
|
847 |
self.default_value = |
|
|
853 | self.default_value = self._resolve_string(self.default_value) | |
|
848 | 854 | |
|
849 | 855 | def get_default_value(self): |
|
850 | 856 | return self.default_value |
@@ -951,7 +957,7 class Instance(ClassBasedTraitType): | |||
|
951 | 957 | |
|
952 | 958 | def _resolve_classes(self): |
|
953 | 959 | if isinstance(self.klass, py3compat.string_types): |
|
954 |
self.klass = |
|
|
960 | self.klass = self._resolve_string(self.klass) | |
|
955 | 961 | |
|
956 | 962 | def get_default_value(self): |
|
957 | 963 | """Instantiate a default value instance. |
@@ -971,17 +977,17 class ForwardDeclaredMixin(object): | |||
|
971 | 977 | """ |
|
972 | 978 | Mixin for forward-declared versions of Instance and Type. |
|
973 | 979 | """ |
|
974 |
def _resolve_ |
|
|
980 | def _resolve_string(self, string): | |
|
975 | 981 | """ |
|
976 | 982 | Find the specified class name by looking for it in the module in which |
|
977 | 983 | our this_class attribute was defined. |
|
978 | 984 | """ |
|
979 | 985 | try: |
|
980 | 986 | modname = self.this_class.__module__ |
|
981 |
|
|
|
987 | return import_item('.'.join([modname, string])) | |
|
982 | 988 | except AttributeError: |
|
983 | 989 | raise ImportError( |
|
984 |
"Module {} has no attribute {}".format(modname, s |
|
|
990 | "Module {} has no attribute {}".format(modname, string) | |
|
985 | 991 | ) |
|
986 | 992 | |
|
987 | 993 | |
@@ -1388,8 +1394,8 class Container(Instance): | |||
|
1388 | 1394 | def instance_init(self, obj): |
|
1389 | 1395 | if isinstance(self._trait, TraitType): |
|
1390 | 1396 | self._trait.this_class = self.this_class |
|
1391 |
if hasattr(self._trait, ' |
|
|
1392 |
self._trait. |
|
|
1397 | if hasattr(self._trait, 'instance_init'): | |
|
1398 | self._trait.instance_init(obj) | |
|
1393 | 1399 | super(Container, self).instance_init(obj) |
|
1394 | 1400 | |
|
1395 | 1401 |
General Comments 0
You need to be logged in to leave comments.
Login now