From c6cc3fc0f6e6400714c67d316f2abf08527ad24e Mon Sep 17 00:00:00 2001 From: dw-0 Date: Sun, 16 Jun 2024 18:57:15 +0200 Subject: [PATCH] Squashed 'kiauh/core/submodules/simple_config_parser/' changes from 188dd1f..4d60d30 4d60d30 refactor: in multiline options we do not replace the option name 0a1fba5 refactor: set default indent to 4 spaces ab522bf refactor: the value of an option can be a list of strings git-subtree-dir: kiauh/core/submodules/simple_config_parser git-subtree-split: 4d60d30a75e7151be7b38b7cdbb2c133711b0091 --- src/simple_config_parser/simple_config_parser.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/simple_config_parser/simple_config_parser.py b/src/simple_config_parser/simple_config_parser.py index 208a630..38cf2d9 100644 --- a/src/simple_config_parser/simple_config_parser.py +++ b/src/simple_config_parser/simple_config_parser.py @@ -185,7 +185,9 @@ class SimpleConfigParser: return self._all_options.get(section) - def get(self, section: str, option: str, fallback: str | _UNSET = _UNSET) -> str: + def get( + self, section: str, option: str, fallback: str | _UNSET = _UNSET + ) -> str | List[str]: """ Return the value of the given option in the given section @@ -260,7 +262,7 @@ class SimpleConfigParser: option: str, value: str, multiline: bool = False, - indent: int = 2, + indent: int = 4, ) -> None: """Set the given option to the given value in the given section @@ -312,8 +314,13 @@ class SimpleConfigParser: else: for _option in self._config[section]["body"]: if _option["option"] == option: - # we preserve inline comments by replacing the old value with the new one - _option["_raw"] = _option["_raw"].replace(_option["value"], _value) + if multiline: + _option["_raw"] = _raw + else: + # we preserve inline comments by replacing the old value with the new one + _option["_raw"] = _option["_raw"].replace( + _option["value"], _value + ) _option["value"] = _value if _raw_value is not None: _option["_raw_value"] = _raw_value