confattr.config module¶
- class confattr.config.Config(key: str, default: T, *, help: Optional[Union[str, dict[T, str]]] = None, unit: Optional[str] = None, parent: Optional[DictConfig[Any, T]] = None, allowed_values: Optional[Sequence[T]] = None)¶
Bases:
Generic[T]Each instance of this class represents a setting which can be changed in a config file.
This class implements the descriptor protocol to return
valueif an instance of this class is accessed as an instance attribute. If you want to get this object you need to access it as a class attribute.- Parameters:
Tcan be one of:a subclass of
enum.Enum(the value used in the config file is the name in lower case letters with hyphens instead of underscores)a class where
__str__()returns a string representation which can be passed to the constructor to create an equal object. If that class has a str attributetype_namethis is used instead of the class name inside of config file. If that class has a str attributehelpthis is used instead of the doc string when explaining the type at the beginning of the config file.a
listof any of the afore mentioned data types. The list may not be empty when it is passed to this constructor so that the item type can be derived but it can be emptied immediately afterwards. (The type of the items is not dynamically enforced—that’s the job of a static type checker—but the type is mentioned in the help.)
- Raises:
ValueError – if key is not unique
- LIST_SEP = ','¶
- default_config_id = 'general'¶
- instances: dict[str, confattr.config.Config[Any]] = {}¶
A mapping of all
Configinstances. The key in the mapping is thekeyattribute. The value is theConfiginstance. NewConfiginstances add themselves automatically in their constructor.
- parse_value_part(t: type[T1], value: str) T1¶
- Raises:
ValueError – if value is invalid
- class confattr.config.ConfigTrackingChanges(key: str, default: T, *, help: Optional[Union[str, dict[T, str]]] = None, unit: Optional[str] = None, parent: Optional[DictConfig[Any, T]] = None, allowed_values: Optional[Sequence[T]] = None)¶
Bases:
Config[T]- Parameters:
Tcan be one of:a subclass of
enum.Enum(the value used in the config file is the name in lower case letters with hyphens instead of underscores)a class where
__str__()returns a string representation which can be passed to the constructor to create an equal object. If that class has a str attributetype_namethis is used instead of the class name inside of config file. If that class has a str attributehelpthis is used instead of the doc string when explaining the type at the beginning of the config file.a
listof any of the afore mentioned data types. The list may not be empty when it is passed to this constructor so that the item type can be derived but it can be emptied immediately afterwards. (The type of the items is not dynamically enforced—that’s the job of a static type checker—but the type is mentioned in the help.)
- Raises:
ValueError – if key is not unique
- has_changed() bool¶
- Returns:
Trueifvaluehas been changed since the last call tosave_value()
- restore_value() None¶
Restore
valueto the value before the last call ofsave_value().
- property value: T¶
- class confattr.config.DictConfig(key_prefix: str, default_values: dict[T_KEY, T], *, ignore_keys: Container[T_KEY] = {}, unit: Optional[str] = None, help: Optional[str] = None, allowed_values: Optional[Sequence[T]] = None)¶
Bases:
Generic[T_KEY,T]- Parameters:
- Raises:
ValueError – if a key is not unique
- class confattr.config.InstanceSpecificDictMultiConfig(dmc: MultiDictConfig[T_KEY, T], config_id: ConfigId)¶
Bases:
Generic[T_KEY,T]
- class confattr.config.MultiConfig(key: str, default: T, *, unit: Optional[str] = None, help: Optional[Union[str, dict[T, str]]] = None, parent: Optional[MultiDictConfig[Any, T]] = None, allowed_values: Optional[Sequence[T]] = None)¶
Bases:
Config[T]- Parameters:
Tcan be one of:a subclass of
enum.Enum(the value used in the config file is the name in lower case letters with hyphens instead of underscores)a class where
__str__()returns a string representation which can be passed to the constructor to create an equal object. If that class has a str attributetype_namethis is used instead of the class name inside of config file. If that class has a str attributehelpthis is used instead of the doc string when explaining the type at the beginning of the config file.a
listof any of the afore mentioned data types. The list may not be empty when it is passed to this constructor so that the item type can be derived but it can be emptied immediately afterwards. (The type of the items is not dynamically enforced—that’s the job of a static type checker—but the type is mentioned in the help.)
- Raises:
ValueError – if key is not unique
- class confattr.config.MultiDictConfig(key_prefix: str, default_values: dict[T_KEY, T], *, ignore_keys: Container[T_KEY] = {}, unit: Optional[str] = None, help: Optional[str] = None, allowed_values: Optional[Sequence[T]] = None)¶
Bases:
DictConfig[T_KEY,T]- Parameters:
- Raises:
ValueError – if a key is not unique