Bug description
ConfigParser.write() outputs UNNAMED_SECTION items after the [DEFAULT] header. When the output is read back, the headerless items appear under [DEFAULT] and are lost from UNNAMED_SECTION.
import configparser, io
US = configparser.UNNAMED_SECTION
cfg = configparser.ConfigParser(allow_unnamed_section=True)
cfg.read_string('key1 = val1\n[DEFAULT]\ndkey = dval\n[sect1]\nkey2 = val2\n')
out = io.StringIO()
cfg.write(out)
cfg2 = configparser.ConfigParser(allow_unnamed_section=True)
cfg2.read_string(out.getvalue())
print('key1' in cfg2[US]) # False -- lost
print('key1' in cfg2.defaults()) # True -- migrated to DEFAULT
CPython versions tested on
3.14, main
Operating systems tested on
macOS
Linked PRs
Bug description
ConfigParser.write()outputsUNNAMED_SECTIONitems after the[DEFAULT]header. When the output is read back, the headerless items appear under[DEFAULT]and are lost fromUNNAMED_SECTION.CPython versions tested on
3.14, main
Operating systems tested on
macOS
Linked PRs