diff --git a/PyFunceble/config/loader.py b/PyFunceble/config/loader.py index 198e99e6..4f994ee8 100644 --- a/PyFunceble/config/loader.py +++ b/PyFunceble/config/loader.py @@ -145,7 +145,7 @@ def wrapper(self, *args, **kwargs): result = func(self, *args, **kwargs) # pylint: disable=not-callable if self.is_already_loaded(): - self.reload() + self.reload(keep_custom=True) return result @@ -519,12 +519,16 @@ def get_configured_value(self, entry: str) -> Any: return PyFunceble.storage.FLATTEN_CONFIGURATION[entry] - def reload(self) -> "ConfigLoader": + def reload(self, keep_custom: bool = False) -> "ConfigLoader": """ Reloads the configuration. + + :param bool keep_custom: + If set to :code:`True`, we keep the custom configuration, otherwise + we delete it. """ - self.destroy() + self.destroy(keep_custom=keep_custom) self.start() def start(self) -> "ConfigLoader": @@ -560,9 +564,13 @@ def start(self) -> "ConfigLoader": return self - def destroy(self) -> "ConfigLoader": + def destroy(self, keep_custom: bool = False) -> "ConfigLoader": """ Destroys everything loaded. + + :param bool keep_custom: + If set to :code:`True`, we keep the custom configuration, otherwise + we delete it. """ try: @@ -577,7 +585,8 @@ def destroy(self) -> "ConfigLoader": except (AttributeError, TypeError): # pragma: no cover ## Safety. pass - # This is not a mistake. - self._custom_config = {} + if not keep_custom: + # This is not a mistake. + self._custom_config = {} return self