Skip to content

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

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

Closed
mtnpke opened this issue Feb 26, 2025 · 2 comments · Fixed by #13544
Closed

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

mtnpke opened this issue Feb 26, 2025 · 2 comments · Fixed by #13544
Labels
stubs: false positive Type checkers report false errors

Comments

@mtnpke
Copy link
Contributor

mtnpke commented Feb 26, 2025

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).
@mtnpke
Copy link
Contributor Author

mtnpke commented Feb 26, 2025

fwiw, replacing types of all section arguments (and the return type of sections()) by str | _UNNAMED_SECTION works for me.

@srittau srittau added the stubs: false positive Type checkers report false errors label Feb 26, 2025
@srittau
Copy link
Collaborator

srittau commented Feb 26, 2025

PR welcome!

mtnpke added a commit to mtnpke/typeshed that referenced this issue Feb 26, 2025
UNNAMED_SECTION was added in Python 3.13 and can be used in place of any
section name. It is not actually a string though, so it needs a
separate type.
@srittau srittau linked a pull request Feb 26, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: false positive Type checkers report false errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants