-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-123049: Allow to create the unnamed section from scratch. #123077
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
Conversation
Misc/NEWS.d/next/Library/2024-08-16-16-53-52.gh-issue-123049.izx_fH.rst
Outdated
Show resolved
Hide resolved
c9c8363
to
450c6c1
Compare
I think now is fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Nice work including the test.
Misc/NEWS.d/next/Library/2024-08-16-16-53-52.gh-issue-123049.izx_fH.rst
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. I just noticed something else. By looking at the docs, I see they no longer match the implementation. We'll want to update the docs to reflect the implementation and also indicate the version changed where UNNAMED_SECTION is allowed (3.14).
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Co-authored-by: Jason R. Coombs <[email protected]>
…zx_fH.rst Co-authored-by: Jason R. Coombs <[email protected]>
Is this ok? .. method:: add_section(section)
Add a section named *section* or :const:`UNNAMED_SECTION` to the instance.
If the given section already exists, :exc:`DuplicateSectionError` is
raised. If :const:`UNNAMED_SECTION` (with `allow_unnamed_section=True` on
:meth:`!__init__`), or if the *default section* name is passed,
:exc:`ValueError` is raised.
Type of *section* is not checked which lets users create non-string named
sections. This behaviour is unsupported and may cause internal errors.
.. versionchanged:: 3.14
Added support for :const:`UNNAMED_SECTION`. |
And the Not great looking code ahead: def _validate_value_types(self, *, section="", option="", value=""):
"""Raises a TypeError for incorrect non-string values.
Legal non-string values are UNNAMED_SECTION and valueless values if
they are are allowed.
For compatibility reasons this method is not used in classic set()
for RawConfigParsers. It is invoked in every case for mapping protocol
access and in ConfigParser.set().
"""
if section is UNNAMED_SECTION:
if not self._allow_unnamed_section:
raise ValueError("UNNAMED_SECTION is not allowed")
else:
if not isinstance(section, str):
raise TypeError("section names must be strings or UNNAMED_SECTION")
if not isinstance(option, str):
raise TypeError("option keys must be strings")
if not self._allow_no_value or value:
if not isinstance(value, str):
raise TypeError("option values must be strings") |
Misc/NEWS.d/next/Library/2024-08-16-16-53-52.gh-issue-123049.izx_fH.rst
Outdated
Show resolved
Hide resolved
…zx_fH.rst Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Thanks for the extended effort!
Co-authored-by: Bénédikt Tran <[email protected]>
Great work everyone. I've backported this functionality to configparser 7.1, so you can utilize the behavior from there until you can rely on Python 3.14. |
Works perfectly! Thanks! |
…om scratch. (python#123077) --------- Co-authored-by: Jason R. Coombs <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
…om scratch. (python#123077) --------- Co-authored-by: Jason R. Coombs <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
May fix #123049.