Skip to main content

ensure_serializable

Ensure items will serialize.

For a given list of arbitrary objects, return the object
or a string representation, safe for serialization.
def ensure_serializable(
items: Iterable[Any],
encoder: Callable
) - > tuple

Ensure items will serialize. For a given list of arbitrary objects, return the object or a string representation, safe for serialization.

Parameters​

NameTypeDescription
itemsIterable[Any]A collection of arbitrary objects to be validated for serialization compatibility.
encoderCallableA function used to test if an object can be successfully serialized.

Returns​

TypeDescription
tupleA tuple containing the original objects if they are serializable, or their safe string representations if they are not.