Skip to main content

generate_encoders_by_class_tuples

Inverts a mapping of types to encoders into a dictionary where each encoder is mapped to a tuple of its associated types.

def generate_encoders_by_class_tuples(
type_encoder_map: dict[Any, Callable[[Any], Any]]
) - > dict[Callable[[Any], Any], tuple[Any, ...]]

Inverts a type-to-encoder mapping to group multiple types under a single shared encoder function. This is used to optimize serialization processes by consolidating types that use identical encoding logic.

Parameters

NameTypeDescription
type_encoder_mapdict[Any, Callable[[Any], Any]]A mapping of specific types to their corresponding serialization functions.

Returns

TypeDescription
dict[Callable[[Any], Any], tuple[Any, ...]]A dictionary where each key is an encoder function and the value is a tuple of all types associated with that encoder.