Skip to content

ConfigParser replaces unnamed section on every read call #127096

Closed
@PalmtopTiger

Description

@PalmtopTiger

Bug report

Bug description:

from configparser import ConfigParser

config = ConfigParser(allow_unnamed_section=True)
config.read(['first.ini', 'second.ini'])

# now the unnamed section contains values ​​only from the second file:
print(config._sections)
# {
# <UNNAMED_SECTION>: {'second_unnamed_option1': '1', 'second_unnamed_option2': '2'},
# 'first_section': {'first_section_option1': '1', 'first_section_option2': '2'},
# 'second_section': {'second_section_option1': '1', 'second_section_option2': '2'}
# }

I think the problem is somewhere here. The unnamed section is recreated on every call.
first.ini.txt
second.ini.txt

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions