8000 configparser: unable to create unnamed section · Issue #123049 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

configparser: unable to create unnamed section #123049

New issue

Have a question about this project? Sign up for a free Git 8000 Hub 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
jaraco opened this issue Aug 15, 2024 · 2 comments · Fixed by #123077
Closed

configparser: unable to create unnamed section #123049

jaraco opened this issue Aug 15, 2024 · 2 comments · Fixed by #123077
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@jaraco
Copy link
Member
jaraco commented Aug 15, 2024

Hi, just chiming in because I really love this new feature - however, I haven't managed to create a new INI file from scratch with an unnamed section yet. Is this possible? Here are my futile attempts with configparser 7.0.0 from backports:

Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun  6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)] on win32
>>> from backports.configparser import UNNAMED_SECTION, ConfigParser
>>> cp = ConfigParser(allow_unnamed_section=True)
>>> cp.set(UNNAMED_SECTION, "option1", "hello world")
Traceback (most recent call last):
    super().set(section, option, value)
    raise NoSectionError(section) from None
backports.configparser.NoSectionError: No section: <UNNAMED_SECTION>
>>> cp.add_section(UNNAMED_SECTION)
  File "C:\Users\kerling\AppData\Local\pypoetry\Cache\virtualenvs\non-package-mode-l42eA81v-py3.12\Lib\site-packages\backports\configparser\__init__.py", line 1294, in _validate_value_types
    raise TypeError("section names must be strings")
TypeError: section names must be strings
>>> cp[UNNAMED_SECTION]["option1"] = "hello world"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\kerling\AppData\Local\pypoetry\Cache\virtualenvs\non-package-mode-l42eA81v-py3.12\Lib\site-packages\backports\configparser\__init__.py", line 1070, in __getitem__
    raise KeyError(key)
KeyError: <UNNAMED_SECTION>
>>> cp[UNNAMED_SECTION] = { "option1": "hello world" }
>>> cp.sections()
['<UNNAMED_SECTION>']
>>> import io
>>> fp = io.StringIO()
>>> cp.write(fp)
>>> fp.getvalue()
'[<UNNAMED_SECTION>]\noption1 = hello world\n\n'

Originally posted by @mtnpke in #66449 (comment)

Linked PRs

@pslacerda
Copy link
Contributor

Hi, I have interest to contribute on this feature.

@jaraco
Copy link
Member Author
jaraco commented Aug 16, 2024

You got it. Let me know if you have any questions.

@picnixz picnixz added type-feature A feature request or enhancement stdlib Python modules in the Lib dir labels Aug 16, 2024
pslacerda added a commit to pslacerda/cpython that referenced this issue Aug 16, 2024
pslacerda added a commit to pslacerda/cpython that referenced this issue Aug 16, 2024
jaraco added a commit that referenced this issue Aug 18, 2024
…atch. (#123077)


---------

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
jeremyhylton pushed a commit to jeremyhylton/cpython that referenced this issue Aug 19, 2024
…om scratch. (python#123077)


---------

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
blhsing pushed a commit to blhsing/cpython that referenced this issue Aug 22, 2024
…om scratch. (python#123077)


---------

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
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-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0