Validates that the value is a valid object instance.
(self, obj: t.Any, value: t.Any)
| 2141 | ) |
| 2142 | |
| 2143 | def validate(self, obj: t.Any, value: t.Any) -> G: |
| 2144 | """Validates that the value is a valid object instance.""" |
| 2145 | if isinstance(value, str): |
| 2146 | try: |
| 2147 | value = self._resolve_string(value) |
| 2148 | except ImportError as e: |
| 2149 | raise TraitError( |
| 2150 | f"The '{self.name}' trait of {obj} instance must be a type, but " |
| 2151 | f"{value!r} could not be imported" |
| 2152 | ) from e |
| 2153 | try: |
| 2154 | if issubclass(value, self.klass): # type:ignore[arg-type] |
| 2155 | return value # type:ignore[no-any-return] |
| 2156 | except Exception: |
| 2157 | pass |
| 2158 | |
| 2159 | self.error(obj, value) |
| 2160 | |
| 2161 | def info(self) -> str: |
| 2162 | """Returns a description of the trait.""" |
nothing calls this directly
no test coverage detected