MCPcopy
hub / github.com/marshmallow-code/marshmallow / _validated

Method _validated

src/marshmallow/fields.py:981–991  ·  view source on GitHub ↗

Format the value or raise a :exc:`ValidationError` if an error occurs.

(self, value: typing.Any)

Source from the content-addressed store, hash-verified

979 return self.num_type(value) # type: ignore[call-arg]
980
981 def _validated(self, value: typing.Any) -> _NumT:
982 """Format the value or raise a :exc:`ValidationError` if an error occurs."""
983 # (value is True or value is False) is ~5x faster than isinstance(value, bool)
984 if value is True or value is False:
985 raise self.make_error("invalid", input=value)
986 try:
987 return self._format_num(value)
988 except (TypeError, ValueError) as error:
989 raise self.make_error("invalid", input=value) from error
990 except OverflowError as error:
991 raise self.make_error("too_large", input=value) from error
992
993 def _to_string(self, value: _NumT) -> str:
994 return str(value)

Callers 1

_deserializeMethod · 0.95

Calls 2

_format_numMethod · 0.95
make_errorMethod · 0.80

Tested by

no test coverage detected