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

Method serialize

src/marshmallow/fields.py:314–340  ·  view source on GitHub ↗

Pulls the value for the given key from the object, applies the field's formatting and returns the result. :param attr: The attribute/key to get from the object. :param obj: The object to access the attribute/key from. :param accessor: Function used to access values f

(
        self,
        attr: str,
        obj: typing.Any,
        accessor: (
            typing.Callable[[typing.Any, str, typing.Any], typing.Any] | None
        ) = None,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

312 raise self.make_error("null")
313
314 def serialize(
315 self,
316 attr: str,
317 obj: typing.Any,
318 accessor: (
319 typing.Callable[[typing.Any, str, typing.Any], typing.Any] | None
320 ) = None,
321 **kwargs,
322 ):
323 """Pulls the value for the given key from the object, applies the
324 field's formatting and returns the result.
325
326 :param attr: The attribute/key to get from the object.
327 :param obj: The object to access the attribute/key from.
328 :param accessor: Function used to access values from ``obj``.
329 :param kwargs: Field-specific keyword arguments.
330 """
331 if self._CHECK_ATTRIBUTE:
332 value = self.get_value(obj, attr, accessor=accessor)
333 if value is missing_:
334 default = self.dump_default
335 value = default() if callable(default) else default
336 if value is missing_:
337 return value
338 else:
339 value = None
340 return self._serialize(value, attr, obj, **kwargs)
341
342 # If value is None, None may be returned
343 @typing.overload

Calls 2

get_valueMethod · 0.95
_serializeMethod · 0.95