confighelper: store deep copies of parsed options

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2024-05-14 18:05:19 -04:00
parent ba9428558a
commit 9c6048a759
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 4 additions and 3 deletions

View File

@ -123,7 +123,7 @@ class ConfigHelper:
) )
def _get_option(self, def _get_option(self,
func: Callable[..., Any], func: Callable[..., _T],
option: str, option: str,
default: Union[Sentinel, _T], default: Union[Sentinel, _T],
above: Optional[Union[int, float]] = None, above: Optional[Union[int, float]] = None,
@ -167,13 +167,14 @@ class ConfigHelper:
f"to section [{self.section}]. Please correct your " f"to section [{self.section}]. Please correct your "
f"configuration, see {help} for detailed documentation." f"configuration, see {help} for detailed documentation."
) )
self._check_option(option, val, above, below, minval, maxval) if isinstance(val, (int, float)):
self._check_option(option, val, above, below, minval, maxval)
if option not in self.parsed[section]: if option not in self.parsed[section]:
if ( if (
val is None or val is None or
isinstance(val, (int, float, bool, str, dict, list)) isinstance(val, (int, float, bool, str, dict, list))
): ):
self.parsed[section][option] = val self.parsed[section][option] = copy.deepcopy(val)
else: else:
# If the item cannot be encoded to json serialize to a string # If the item cannot be encoded to json serialize to a string
self.parsed[section][option] = str(val) self.parsed[section][option] = str(val)