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

Method validate_elements

traitlets/traitlets.py:3822–3841  ·  view source on GitHub ↗
(self, obj: t.Any, value: t.Any)

Source from the content-addressed store, hash-verified

3820 return self._traits[index].from_string(s)
3821
3822 def validate_elements(self, obj: t.Any, value: t.Any) -> t.Any:
3823 if not self._traits:
3824 # nothing to validate
3825 return value
3826 if len(value) != len(self._traits):
3827 e = (
3828 "The '%s' trait of %s instance requires %i elements, but a value of %s was specified."
3829 % (self.name, class_of(obj), len(self._traits), repr_type(value))
3830 )
3831 raise TraitError(e)
3832
3833 validated = []
3834 for trait, v in zip(self._traits, value):
3835 try:
3836 v = trait._validate(obj, v)
3837 except TraitError as error:
3838 self.error(obj, v, error)
3839 else:
3840 validated.append(v)
3841 return tuple(validated)
3842
3843 def class_init(self, cls: type[t.Any], name: str | None) -> None:
3844 for trait in self._traits:

Callers

nothing calls this directly

Calls 6

class_ofFunction · 0.85
repr_typeFunction · 0.85
TraitErrorClass · 0.85
_validateMethod · 0.80
errorMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected