Skip to content

configparser: create unnamed section with mapping protocol access #136282

Closed

Description

@Rogdham

Feature or enhancement

Current state (3.14):

Since gh-123077 (CPython 3.14), it is possible to create an unnamed section with configparser:

>>> cfg1 = configparser.ConfigParser(allow_unnamed_section=True)
>>> cfg1.add_section(configparser.UNNAMED_SECTION)
>>> cfg1.set(configparser.UNNAMED_SECTION, "foo", "bar")
>>> cfg1.write(fobj1)

This gives the following output file:

foo = bar

However, the mapping protocol access is not supported:

>>> cfg2 = configparser.ConfigParser(allow_unnamed_section=True)
>>> cfg2[configparser.UNNAMED_SECTION] = {"foo": "bar"}
>>> cfg2.write(fobj2)

Gives the following output file:

[<UNNAMED_SECTION>]
foo = bar


Proposal:

Implement the mapping protocol for access of the unnamed section in configparser.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Jul 4, 2025
  2. added a commit that references this issue on Jul 5, 2025
  3. merwok commented on Nov 27, 2025

    @merwok
    Member

    I am not sure this should be a feature: I can’t see someone wanting the current behaviour.

  4. merwok commented on Nov 27, 2025

    @merwok
    Member

    @ambv (for configparser) and @hugovk (RM), would you call this a feature or fix?

  5. added a commit that references this issue on Dec 19, 2025
  6. added a commit that references this issue on Dec 19, 2025
  7. added a commit that references this issue on Dec 22, 2025
  8. added a commit that references this issue on Jan 6, 2026
  9. encukou commented on Jan 6, 2026

    @encukou
    Member

    Thank you for the fix!

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-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions