Skip to content

ConfigParser: writing a config with an empty unnamed section adds an extra newline to the beginning of the file #129678

@PalmtopTiger

Description

@PalmtopTiger

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions