Bug report
Bug description:
If you read a config with an empty unnamed section using ConfigParser with allow_unnamed_section set to True and write it back, the resulting file will contain an extra newline at the beginning:
from configparser import ConfigParser
from io import StringIO
cfg = ConfigParser(allow_unnamed_section=True)
cfg.read_string('[sect]')
output = StringIO()
cfg.write(output)
print(repr(output.getvalue())) # '\n[sect]\n\n'
CPython versions tested on:
3.13
Operating systems tested on:
Windows
Linked PRs