partis.schema.prim.union_prim module#

class UnionPrimDeclared(name=None, module=None, module_set=None, doc=None, **kwargs)[source]#

Bases: SchemaPrimDeclared

class UnionPrim(name=None, module=None, module_set=None, doc=None, **kwargs)[source]#

Bases: SchemaPrim

Primitive for union of types values

Parameters:
  • cases (list[ SchemaStruct | SchemaPrim ]) –

    Schemas that are considered for decoding a value. The union of schemas may not be ambiguous, restricting the combinations to

    • Max of one case of BoolPrim.

    • Max of one numeric case of either IntPrim or FloatPrim.

    • Max of one case of StrPrim.

    • Max of one case of SeqPrim.

    • Max of one case of MapPrim.

    • May not have cases of both MapPrim and SchemaStruct.

    • All cases of SchemaStruct must be defined with the same tag_key, and no cases with a nested struct_proxy.

    • May not have any case of PassPrim

  • default_case (NoneType | int) – Case to use for default value when source data is not available, including if the case’s default_val is required or optional.

  • **kwargs (arguments passed to SchemaPrim) –

default_val#
default_eval#
init_val#
property hints#

Definition hints.

Type:

list[ SchemaHint ]

encode(val=None, loc=None, no_defaults=None)[source]#

Encodes value to basic Python types, performing validation

Parameters:
  • val (None | object) – Source data used to initialize values

  • loc (None | Loc) – Location information of source data (E.G. file, line/column number)

  • no_defaults (bool) – Values that are equivalent to the ‘default_val’ are removed.

Returns:

val (object)

Raises:

SchemaValidationError – If the value is not valid

decode(val=None, loc=None, bias=None)[source]#

Decodes value to schema values, performing validation

Parameters:
  • val (None | object) – Source data used to initialize values

  • loc (None | Loc) – Location information of source data (E.G. file, line/column number)

  • bias (None | Bias) –

Returns:

val (Valued)

Raises:

SchemaValidationError – If the value is not valid