diff --git a/src/simple_config_parser/simple_config_parser.py b/src/simple_config_parser/simple_config_parser.py index 3275bf3..b3f10c6 100644 --- a/src/simple_config_parser/simple_config_parser.py +++ b/src/simple_config_parser/simple_config_parser.py @@ -192,9 +192,9 @@ class SimpleConfigParser: if section not in self._all_sections: raise NoSectionError(section) - del self._all_sections[self._all_sections.index(section)] - del self._all_options[section] - del self._config[section] + self._all_sections.pop(self._all_sections.index(section)) + self._all_options.pop(section) + self._config.pop(section) def options(self, section) -> List[str]: """Return a list of option names for the given section name""" @@ -453,6 +453,7 @@ class SimpleConfigParser: self.section_name = section self._all_sections.append(section) + self._all_options[section] = {} self._config[section]: Section = {"_raw": raw_value, "body": []} def _parse_option(self, line: str) -> None: diff --git a/tests/features/internal_state/test_internal_state_changes.py b/tests/features/internal_state/test_internal_state_changes.py index af32e1e..789368c 100644 --- a/tests/features/internal_state/test_internal_state_changes.py +++ b/tests/features/internal_state/test_internal_state_changes.py @@ -34,6 +34,7 @@ class TestInternalStateChanges: parser._store_internal_state_section(given, given) assert parser._all_sections == [given] + assert parser._all_options[given] == {} assert parser._config[given]["body"] == [] assert parser._config[given]["_raw"] == given