Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
PalmtopTiger opened this issue Feb 5, 2025 · 2 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@PalmtopTiger
Copy link
Contributor

PalmtopTiger commented Feb 5, 2025

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

@PalmtopTiger PalmtopTiger added the type-bug An unexpected behavior, bug, or error label Feb 5, 2025
@encukou encukou added the stdlib Python modules in the Lib dir label Feb 5, 2025
encukou added a commit to PalmtopTiger/cpython that referenced this issue Feb 14, 2025
@encukou
Copy link
Member

encukou commented Feb 17, 2025

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.

@encukou encukou closed this as completed Feb 17, 2025
@PalmtopTiger
Copy link
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants