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:
SchemaPrimPrimitive 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 case of
StrPrim.Max of one case of
SeqPrim.Max of one case of
MapPrim.May not have cases of both
MapPrimandSchemaStruct.All cases of
SchemaStructmust 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:
- Returns:
val (object)
- Raises:
SchemaValidationError – If the value is not valid