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

Method _deserialize

src/marshmallow/schema.py:597–706  ·  view source on GitHub ↗

Deserialize ``data``. :param data: The data to deserialize. :param error_store: Structure to store errors. :param many: `True` if ``data`` should be deserialized as a collection. :param partial: Whether to ignore missing fields and not require any fields

(
        self,
        data: Mapping[str, typing.Any] | Sequence[Mapping[str, typing.Any]],
        *,
        error_store: ErrorStore,
        many: bool = False,
        partial=None,
        unknown: types.UnknownOption = RAISE,
        index=None,
    )

Source from the content-addressed store, hash-verified

595 return self.opts.render_module.dumps(serialized, *args, **kwargs)
596
597 def _deserialize(
598 self,
599 data: Mapping[str, typing.Any] | Sequence[Mapping[str, typing.Any]],
600 *,
601 error_store: ErrorStore,
602 many: bool = False,
603 partial=None,
604 unknown: types.UnknownOption = RAISE,
605 index=None,
606 ) -> typing.Any | list[typing.Any]:
607 """Deserialize ``data``.
608
609 :param data: The data to deserialize.
610 :param error_store: Structure to store errors.
611 :param many: `True` if ``data`` should be deserialized as a collection.
612 :param partial: Whether to ignore missing fields and not require
613 any fields declared. Propagates down to ``Nested`` fields as well. If
614 its value is an iterable, only missing fields listed in that iterable
615 will be ignored. Use dot delimiters to specify nested fields.
616 :param unknown: Whether to exclude, include, or raise an error for unknown
617 fields in the data. Use `EXCLUDE`, `INCLUDE` or `RAISE`.
618 :param index: Index of the item being serialized (for storing errors) if
619 serializing a collection, otherwise `None`.
620 :return: The deserialized data as `dict_class` instance or list of `dict_class`
621 instances if `many` is `True`.
622 """
623 index_errors = self.opts.index_errors
624 index = index if index_errors else None
625 if many:
626 if not is_sequence_but_not_string(data):
627 error_store.store_error([self.error_messages["type"]], index=index)
628 ret_l = []
629 else:
630 ret_l = [
631 self._deserialize(
632 d,
633 error_store=error_store,
634 many=False,
635 partial=partial,
636 unknown=unknown,
637 index=idx,
638 )
639 for idx, d in enumerate(data)
640 ]
641 return ret_l
642 ret_d = self.dict_class()
643 # Check data is a dict
644 if not isinstance(data, Mapping):
645 error_store.store_error([self.error_messages["type"]], index=index)
646 else:
647 partial_is_collection = is_collection(partial)
648 for attr_name, field_obj in self.load_fields.items():
649 field_name = (
650 field_obj.data_key if field_obj.data_key is not None else attr_name
651 )
652 raw_value = data.get(field_name, missing)
653 if raw_value is missing:
654 # Ignore missing field if we're allowed to.

Callers 1

_do_loadMethod · 0.95

Calls 6

_call_and_storeMethod · 0.95
is_collectionFunction · 0.90
set_valueFunction · 0.90
store_errorMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected