torchoutil.serialization.common module

to_builtin(
x: Enum,
*,
unk_mode: Literal['identity', 'error'] = 'error',
) str[source]
to_builtin(
x: Path,
*,
unk_mode: Literal['identity', 'error'] = 'error',
) str
to_builtin(
x: Pattern,
*,
unk_mode: Literal['identity', 'error'] = 'error',
) str
to_builtin(
x: Namespace,
*,
unk_mode: Literal['identity', 'error'] = 'error',
) Dict[str, Any]
to_builtin(
x: Tensor,
*,
unk_mode: Literal['identity', 'error'] = 'error',
) List | bool | int | float | complex
to_builtin(
x: Mapping[K, V],
*,
unk_mode: Literal['identity', 'error'] = 'error',
) Dict[K, V]
to_builtin(
x: DataclassInstance,
*,
unk_mode: Literal['identity', 'error'] = 'error',
) Dict[str, Any]
to_builtin(
x: NamedTupleInstance,
*,
unk_mode: Literal['identity', 'error'] = 'error',
) Dict[str, Any]
to_builtin(
x: T_BuiltinScalar,
*,
unk_mode: Literal['identity', 'error'] = 'error',
) T_BuiltinScalar
to_builtin(
x: Any,
*,
unk_mode: Literal['identity', 'error'] = 'error',
) Any

Convert an object to a python builtin equivalent.

This function can be used to sanitize data before saving to YAML or CSV file.

Args:

x: Object to convert to built-in equivalent. unk_mode: When an object type is not recognized, unk_mode defines the behaviour.

If unk_mode == “identity”, the object is returned unchanged. If unk_mode == “error”, a TypeError is raised.