yera.typing.coerce

Coercion utilities to convert raw input values and python objects into their annotated types.

Symbols

def coerce_input — Coerce an app input value to its declared type.

coerce_input

coerce_input(
    value: object,
    type_hint: type,
    mode: Literal['json', 'python'],
) → object

Coerce an app input value to its declared type.

Parameters

value
type: object

The input value.

type_hint
type: type

The resolved annotation to coerce to.

mode
type: Literal['json', 'python']

Whether value arrived as a wire string or a Python object.

Returns

type: object

The coerced value.

Raises

TypeError

If type_hint is not an allowed type.

ValueError

If value cannot be coerced.