From 93b06d612733ba200f7b18b28be2d8cb3188fc2a Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 13 Mar 2023 19:12:47 +0100 Subject: [PATCH] ConfigurableObject: add set_default() / set_defaults() methods --- mylib/config.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mylib/config.py b/mylib/config.py index 2f8927e..f60f0d0 100644 --- a/mylib/config.py +++ b/mylib/config.py @@ -1156,6 +1156,16 @@ class ConfigurableObject: 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): """Configure options on registered mylib.Config object""" assert self._config, (