egrecho.core.config#
- class egrecho.core.config.DataclassConfig[source]#
Bases:
ConfigFileMixin
,DataclassSerialMixin
Base class for
dataclass
configuration.Surely we could directly interact args in
dataclass
with outsideargparse
cli. However, cli can hardly parse nest cases (e.g., dict, nest sequence, etc.). What’more, adding all args to cli is redundant. So our configs folllow below rules:- We abandon the
InitVar
set fordataclasses
, sinceInitVar
is tricky to serialize/deserialize.
- We abandon the
- additional keys in fields’ metadata:
‘to_dict’: if set False, will be ignored when serialization. defaults to True.
‘encoding_fn’: custom fn when serialization.
‘decoding_fn’: custom fn when desrialization.
- classmethod from_config(config=None, strict=False, **kwargs)[source]#
Creates an instance from config.
Input
config
can be an instance or a dict, the invalid overwrite args in **kwargs will be informed and ignored ifstrict=True
.- Parameters:
config (Union[dict, DataclassConfig]) -- The configuration.
strict (
bool
) -- if True, raise exception if got unexpected arguments. Defautls to False.
- Returns:
The new config instance.
- Return type: