Skip to content

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

Closed

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

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Feb 5, 2025
  2. added 2 commits that reference this issue on Feb 14, 2025
  3. encukou commented on Feb 17, 2025

    @encukou
    Member

    Thank you! Merged to the 3.14 branch.
    I don't think this is a bug, though.

    To avoid a point release changing the output, I'll not backport to 3.13.

  4. PalmtopTiger commented on Feb 17, 2025

    @PalmtopTiger
    ContributorAuthor

    Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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