Skip to content

configparser.UNNAMED_SECTION cannot be used with ConfigParser section API #13542

@mtnpke

Description

@mtnpke

configparser.UNNAMED_SECTION has been introduced in Python 3.13. It is "A special object representing a section name used to reference the unnamed section".

A specific example of usage is given in the documentation:

import configparser
config = """
option = value

[  Section 2  ]
another = val
"""
unnamed = configparser.ConfigParser(allow_unnamed_section=True)
unnamed.read_string(config)
unnamed.get(configparser.UNNAMED_SECTION, 'option')

This currently fails to typecheck since as all section arguments are typed as str. However, UNNAMED_SECTION is not an str. See for example here and here.
See also this example in the Pyright Playground giving:

Argument of type "_UNNAMED_SECTION" cannot be assigned to parameter "section" of type "str" in function "get"
  "_UNNAMED_SECTION" is not assignable to "str"  (reportArgumentType).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions