diff options
author | Andrey Efremov <duxus@yandex.ru> | 2025-01-27 01:33:07 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-26 13:33:07 -0500 |
commit | 914c232e9391e8e5014b089ba12c75d4a3b0cc7f (patch) | |
tree | 1ab8add0c27b5f4f2051144ce6da2f08a09ee6d9 /Lib/configparser.py | |
parent | 5d9b62005a110164c6be5bf412d344917e872e10 (diff) | |
download | cpython-914c232e9391e8e5014b089ba12c75d4a3b0cc7f.tar.gz cpython-914c232e9391e8e5014b089ba12c75d4a3b0cc7f.zip |
gh-127096: Do not recreate unnamed section on every read in ConfigParser (#127228)
* Do not recreate unnamed section on every read in ConfigParser
* Remove duplicate section creation code
Diffstat (limited to 'Lib/configparser.py')
-rw-r--r-- | Lib/configparser.py | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/Lib/configparser.py b/Lib/configparser.py index 420dce77c23..9dc4fa515cf 100644 --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -1105,11 +1105,7 @@ class RawConfigParser(MutableMapping): def _handle_rest(self, st, line, fpname): # a section header or option header? if self._allow_unnamed_section and st.cursect is None: - st.sectname = UNNAMED_SECTION - st.cursect = self._dict() - self._sections[st.sectname] = st.cursect - self._proxies[st.sectname] = SectionProxy(self, st.sectname) - st.elements_added.add(st.sectname) + self._handle_header(st, UNNAMED_SECTION, fpname) st.indent_level = st.cur_indent_level # is it a section header? @@ -1118,10 +1114,10 @@ class RawConfigParser(MutableMapping): if not mo and st.cursect is None: raise MissingSectionHeaderError(fpname, st.lineno, line) - self._handle_header(st, mo, fpname) if mo else self._handle_option(st, line, fpname) + self._handle_header(st, mo.group('header'), fpname) if mo else self._handle_option(st, line, fpname) - def _handle_header(self, st, mo, fpname): - st.sectname = mo.group('header') + def _handle_header(self, st, sectname, fpname): + st.sectname = sectname if st.sectname in self._sections: if self._strict and st.sectname in st.elements_added: raise DuplicateSectionError(st.sectname, fpname, |