Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-66449: Add support to unnamed sections in ConfigParser#2735

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
pslacerda wants to merge9 commits intopython:mainfrompslacerda:fix-issue-issue22253
Closed

gh-66449: Add support to unnamed sections in ConfigParser#2735

pslacerda wants to merge9 commits intopython:mainfrompslacerda:fix-issue-issue22253

Conversation

pslacerda
Copy link
Contributor

@pslacerdapslacerda commentedJul 16, 2017
edited by bedevere-bot
Loading

Add support to files that have key-value pairs before any section or no section at all. Unnamed sections are enabled when passingallow_unnamed_section=True toconfigparser.ConfigParser and are stored as an empty string.

OlegSchwann, johnlinp, ptman, kernc, septatrix, castro12321, ottok, martinschneider, arhadthedev, McSinyx, and 7 more reacted with thumbs up emoji
@the-knights-who-say-ni

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed thePSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username onbugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please followthe steps outlined in the CPython devguide to rectify this issue.

Thanks again to your contribution and we look forward to looking at it!

@serhiy-storchakaserhiy-storchaka added the type-featureA feature request or enhancement labelDec 8, 2018
@ottok
Copy link

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actionsgithub-actionsbot added the staleStale PR or inactive for long period of time. labelFeb 20, 2022
@ottok
Copy link

This PR should be merged and not closed for being "stale".

@github-actionsgithub-actionsbot removed the staleStale PR or inactive for long period of time. labelFeb 21, 2022
Copy link
Contributor

@MaxwellDupreMaxwellDupre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Both test cases were successful:
test_no_first_section (Lib.test.test_configparser.SectionlessTestCase) ... ok test_no_section (Lib.test.test_configparser.SectionlessTestCase) ... ok
SO examples work, but if you print the key you get DEFAULT and if you want to see theget() you need to use a blank key ''.

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actionsgithub-actionsbot added the staleStale PR or inactive for long period of time. labelMar 25, 2022
@ChristianSi
Copy link

Why is this not merged yet? It would be great to have!

arhadthedev, rwoloszyn, and j-karls reacted with thumbs up emoji

@arhadthedev
Copy link
Member

arhadthedev commentedJul 1, 2022
edited
Loading

@ChristianSi Probably because#2735 (review) is not addressed.

@arhadthedev
Copy link
Member

This PR is stuck for five years, so cc@ambv as a configparser expert.

hiarcs reacted with thumbs up emoji

@github-actionsgithub-actionsbot removed the staleStale PR or inactive for long period of time. labelJul 2, 2022
@ChristianSi
Copy link

Any news on this one?

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actionsgithub-actionsbot added the staleStale PR or inactive for long period of time. labelSep 2, 2022
@ChristianSi
Copy link

@pslacerda It seems this PR got stalled because you didn't address theproposal to use a sentinel object instead of the empty string (as per your own suggestion).

Could you implement that change to get this moving again? Also, the branch would have be to rebased or main merged into it to get it up-to-date.

Would be great if we could finally get this completed!

@github-actionsgithub-actionsbot added the staleStale PR or inactive for long period of time. labelApr 9, 2023
@github-actionsgithub-actionsbot removed the staleStale PR or inactive for long period of time. labelApr 10, 2023
@ChristianSi
Copy link

@arhadthedev Good to read from you. Could you maybe help us to get this finally merged into main?

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actionsgithub-actionsbot added the staleStale PR or inactive for long period of time. labelMay 11, 2023
@arhadthedevarhadthedev changed the titlebpo-22253: Add support to unnamed sections in ConfigParsergh-66449: Add support to unnamed sections in ConfigParserMay 11, 2023
@github-actionsgithub-actionsbot removed the staleStale PR or inactive for long period of time. labelMay 12, 2023
@ChristianSi

This comment was marked as abuse.

@arhadthedev
Copy link
Member

I give up on this, but not without publicly naming and shaming@ambv for not doing his job as the apparent maintainer of this part of the standard library.

Even with big desire, nobody can merge any new feature until 3.12b1 is out. The release date is already urgently moved from the last Monday to May 22. Fromhttps://discuss.python.org/t/postponing-3-12-beta-1-feature-freeze/26406:

Considering how many accepted changes are still being worked on (PEPs 684, 687, 688, 695, 697 at least) and still being decided on by the SC (PEPs 649, 702 and 709), I’m planning to postpone feature freeze and beta 1 for 3.12 by two weeks, without changing the rest of the schedule.

For the record: the postponement is just for the changes already in flight. Please don’t try to squeeze in more features because we have two more weeks. (Bugfixes are fine, of course.)

j-karls reacted with thumbs down emoji

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

ptman and j-karls reacted with confused emoji

@github-actionsgithub-actionsbot added the staleStale PR or inactive for long period of time. labelJun 17, 2023
@furkanonderfurkanonder added stdlibPython modules in the Lib dir staleStale PR or inactive for long period of time. and removed staleStale PR or inactive for long period of time. labelsAug 6, 2023
Copy link
Member

@vadmiumvadmium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

As well clarifying whether headerless options should leak into other sections, maybe there should be tests and documentation for the behaviour of:

  • config.add_section(TOP_LEVEL)
  • config[TOP_LEVEL] = ...
  • Creating and retrieving TOP_LEVEL section when reading headerless section not enabled
  • Using TOP_LEVEL as a regular name, e.g. sorted(config.keys())

@@ -68,6 +69,12 @@
converter gets its corresponding get*() method on the parser object and
section proxies.

When `allow_unnamed_section` is True (default: False), options
without section are accepted: the section for this is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

options withouta section?

return "<TOP_LEVEL>"

def __eq__(self, other):
return repr(self) == repr(other)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why did__eq__ get implemented? It makes more sense to me to keep the default inherited implementation. Doesn’t the class only get instantiated once anyway?

Won’t this make a valid section headed [<TOP_LEVEL>] match the headerless section in some cases?

@@ -0,0 +1,4 @@
:class:`configparser.ConfigParser` now accepts unnamed sections before named
ones, if configured to do so.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

“acceptsan unnamedsection before named ones” might be clearer

@@ -68,6 +69,12 @@
converter gets its corresponding get*() method on the parser object and
section proxies.

When `allow_unnamed_section` is True (default: False), options
without section are accepted: the section for this is
``configparser.UNNAMED_SECTION``. In the file, they are placed before
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

configparser.TOP_LEVEL?

@@ -18,7 +18,8 @@
delimiters=('=', ':'), comment_prefixes=('#', ';'),
inline_comment_prefixes=None, strict=True,
empty_lines_in_values=True, default_section='DEFAULT',
interpolation=<unset>, converters=<unset>):
interpolation=<unset>, converters=<unset>,
allow_unnamed_section=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

allow_unnamed_section not implemented

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This seems ok.

@github-actionsgithub-actionsbot removed the staleStale PR or inactive for long period of time. labelMar 24, 2024
@hw-claudio
Copy link

this feature would be very important to integrate. Is it available yet?
Note that a lot of the comments in the issue thread related to this are incorrect when they argue that this is not how INI files work.

The Windows INI files and the GetProfileString family of APIs have had this undocumented behavior forever, where an empty section is absolutely present and used by software.

See the following wine commits and bugs related to it:

wine-mirror/wine@be678a5
https://bugs.winehq.org/show_bug.cgi?id=8036
https://bugs.winehq.org/show_bug.cgi?id=18099

I would like to use ConfigParser, but currently cannot due to this missing feature, so I am open coding the config file parsing, which I would gladly avoid.

ChristianSi reacted with thumbs up emoji

@ChristianSi
Copy link

@vadmium Thanks for your review!

@pslacerda Are you still around and willing to make the changes suggested in the review? They seem quite reasonable to me.

@ChristianSi
Copy link

ChristianSi commentedMar 26, 2024
edited
Loading

@hw-claudio I alsolutely agree, it would be great to have!

Sadly it seems that it's a low-prio, or even a no-prio feature for Python's core developers 😢

@pslacerda
Copy link
ContributorAuthor

I don't even remember the original motivation why I did this PR.

I failed to merge into this PR, so I did a new one.

#117273

ChristianSi reacted with rocket emoji

@pslacerda
Copy link
ContributorAuthor

Finally seems that we will get this code into main. Thank you@ChristianSi!

ChristianSi reacted with rocket emoji

@ChristianSi
Copy link

@pslacerda Wow, that's wonderful news, thanks a lot for all your effort!

Co-authored-by: Furkan Onder <furkanonder@protonmail.com>
@pslacerda
Copy link
ContributorAuthor

Thank you@ChristianSi and@jaraco, it finally got merged.

#117273

drew-parsons reacted with hooray emojiChristianSi reacted with rocket emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@vadmiumvadmiumvadmium left review comments

@MichalCabMichalCabMichalCab left review comments

@furkanonderfurkanonderfurkanonder left review comments

@csabellacsabellacsabella left review comments

@ChristianSiChristianSiChristianSi approved these changes

@MaxwellDupreMaxwellDupreMaxwellDupre approved these changes

Assignees
No one assigned
Labels
awaiting core reviewstdlibPython modules in the Lib dirtype-featureA feature request or enhancement
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

18 participants
@pslacerda@the-knights-who-say-ni@ottok@ChristianSi@arhadthedev@ambv@drew-parsons@hw-claudio@vadmium@MichalCab@MaxwellDupre@furkanonder@csabella@brettcannon@serhiy-storchaka@Mariatta@ezio-melotti@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp