ConfigurableObject: add set_default() / set_defaults() methods

This commit is contained in:
Benjamin Renard 2023-03-13 19:12:47 +01:00
parent e71fb28295
commit 93b06d6127
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -1156,6 +1156,16 @@ class ConfigurableObject:
return default if default is not None else self._defaults.get(option) return default if default is not None else self._defaults.get(option)
def set_default(self, option, default_value):
"""Set option default value"""
assert option in self._defaults, f"Unkown option {option}"
self._defaults[option] = default_value
def set_defaults(self, **default_values):
"""Set options default value"""
for option, default_value in default_values.items():
self.set_default(option, default_value)
def configure(self, comment=None, **kwargs): def configure(self, comment=None, **kwargs):
"""Configure options on registered mylib.Config object""" """Configure options on registered mylib.Config object"""
assert self._config, ( assert self._config, (