eyconf.config.extra_fields.ConfigExtra¶
- class eyconf.config.extra_fields.ConfigExtra(data: dict | D, schema: type[D] | None = None)¶
Configuration class that supports extra fields explicitly.
This class extends the base configuration functionality to allow for additional fields that are not defined in the original schema.
This additional fields are accessible via the extra_data property. They are merged into the schema data when accessing via the data property.
Attributes
Get the configuration data wrapped in a dynamic accessor.
Get the extra data as a dict.
Convenience Property for setting non-schema fields.
Get the schema dataclass type excluding extra fields.
Methods
__init__(data[, schema])overwrite(data)Overwrite the configuration with provided data.
reset()Reset the configuration data to the default values.
to_dict([extra_fields])Get the full configuration data as a dictionary, including extra fields.
to_yaml()Convert the configuration data to a yaml string.
update(data)Update the configuration with provided data.
validate()Validate the current data against the schema.
- property data: D¶
Get the configuration data wrapped in a dynamic accessor.
Care: Instance checks will not work as expected on this property.
We have two non-ideal choices for the type hint here: - if we use D, we will get a wrong type_error for e.g. config.data.my_field.to_dict() - if we use AccessProxy[D], we wont get the nice type_checking against the schema.
- overwrite(data: dict | D)¶
Overwrite the configuration with provided data.
If the provided data is missing required fields, an error will be raised.
- property proxy: AccessProxy[D]¶
Convenience Property for setting non-schema fields.
- reset()¶
Reset the configuration data to the default values.
- property schema_data: D¶
Get the schema dataclass type excluding extra fields.
- to_dict(extra_fields: bool = True) dict¶
Get the full configuration data as a dictionary, including extra fields.
- update(data: dict[str, Any])¶
Update the configuration with provided data.
This applies an partial update to the existing configuration data. Only the provided keys will be updated, others will remain unchanged.
- validate()¶
Validate the current data against the schema.