yera.typing.codecs

Pydantic codecs for types that need custom JSON handling.

DataFrames, Series and dicts with non-JSON-safe keys serialise through the codecs here. substitute_types attaches them to a type hint, and make_adapter builds the adapter the rest of yera.typing uses.

Symbols

def make_adapter — Build a pydantic adapter for a type hint with Yera's JSON settings.
def substitute_types — Attach Yera's codecs to the parts of a type hint that need them.

make_adapter

make_adapter(
    tp: TypeHint,
) → TypeAdapter[object]

Build a pydantic adapter for a type hint with Yera's JSON settings.

Parameters

tp
type: TypeHint

The type hint, with codecs already attached.

Returns

type: TypeAdapter[object]

A TypeAdapter for tp.

substitute_types

substitute_types(
    tp: TypeHint,
) → TypeHint

Attach Yera's codecs to the parts of a type hint that need them.

DataFrame and Series annotations gain their codec, and dicts whose keys are not JSON-safe are wrapped in the mapping codec, recursively through unions, Annotated, tuples, dicts and other generics.

Parameters

tp
type: TypeHint

The type hint to rewrite.

Returns

type: TypeHint

The same hint, with codecs attached where required.