dataclass_builder.utility module¶
Utility functions for the package.
-
dataclass_builder.utility.build(builder: dataclass_builder.wrapper.DataclassBuilder) → Any[source]¶ Use the given
DataclassBuilderto initialize a dataclass.This will use the values assigned to the given builder to construct a
dataclasses.dataclass()of the type the builder was created for.Note
This is not a method of
DataclassBuilderin order to not interfere with possible field names. This function will use special private methods ofDataclassBuilderwhich are excepted from field assignment.- Parameters
builder – The dataclass builder to build from.
- Raises
dataclass_builder.exceptions.MissingFieldError – If not all of the required fields have been assigned to this builder.
-
dataclass_builder.utility.fields(builder: dataclass_builder.wrapper.DataclassBuilder, *, required: bool = True, optional: bool = True) → Mapping[str, Field[Any]][source]¶ Get a dictionary of the given
DataclassBuilder’s fields.Note
This is not a method of
DataclassBuilderin order to not interfere with possible field names. This function will use special private methods ofDataclassBuilderwhich are excepted from field assignment.- Parameters
builder – The dataclass builder to get the fields for.
required – Set to False to not report required fields.
optional – Set to False to not report optional fields.
- Returns
A mapping from field names to actual
dataclasses.Field’s in the same order as the builder’s underlyingdataclasses.dataclass().
-
dataclass_builder.utility.update(dataclass: Any, builder: dataclass_builder.wrapper.DataclassBuilder) → None[source]¶ Update a dataclass or dataclass builder from a partial dataclass builder.
- Parameters
dataclass –
:func`dataclasses.dataclass` or dataclass builder to update.
Note
Technically this can be any object that supports
__setattr__().builder – The datalcass builder to update dataclass with. All fields that are not missing in the builder will be set (overridden) on the given dataclass.