MCPcopy Create free account
hub / github.com/ipython/traitlets / validate

Method validate

traitlets/traitlets.py:2143–2159  ·  view source on GitHub ↗

Validates that the value is a valid object instance.

(self, obj: t.Any, value: t.Any)

Source from the content-addressed store, hash-verified

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."""

Callers

nothing calls this directly

Calls 3

TraitErrorClass · 0.85
errorMethod · 0.80
_resolve_stringMethod · 0.45

Tested by

no test coverage detected