GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-66449: Add support to unnamed sections in ConfigParser by pslacerda · Pull Request #2735 · python/cpython

Conversation

@pslacerda

@pslacerda pslacerda commented Jul 16, 2017 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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

  • Issue: ConfigParser does not handle files without sections #66449

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

the-knights-who-say-ni commented Jul 16, 2017

Copy link
Copy Markdown

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 the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.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 follow the steps outlined in the CPython devguide to rectify this issue.

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@the-knights-who-say-ni the-knights-who-say-ni added the CLA not signed label Jul 16, 2017
MichalCab
MichalCab reviewed Jul 16, 2017
View reviewed changes
Comment thread Lib/configparser.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@the-knights-who-say-ni the-knights-who-say-ni added CLA signed and removed CLA not signed labels Jul 16, 2017
csabella
csabella reviewed Jul 18, 2017
View reviewed changes
Comment thread Lib/configparser.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

csabella
csabella reviewed Jul 18, 2017
View reviewed changes
Comment thread Lib/configparser.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Mariatta Mariatta added needs rebase and removed needs rebase labels Oct 9, 2017
@brettcannon brettcannon added the awaiting review label Feb 2, 2018
@serhiy-storchaka serhiy-storchaka added the type-feature A feature request or enhancement label Dec 8, 2018
@ottok

ottok commented Apr 25, 2021

Copy link
Copy Markdown

This PR closes https://bugs.python.org/issue22253 from 2014

While waiting for this change to land in Python, a huge amount of people seem to use these workarounds:

  • https://stackoverflow.com/questions/2819696/parsing-properties-file-in-python
  • https://stackoverflow.com/questions/22501121/configparser-missingsectionheadererror-when-parsing-rsyncd-config-file-with-glob
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Feb 20, 2022

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Feb 20, 2022
@ottok

ottok commented Feb 20, 2022

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Feb 21, 2022
MaxwellDupre
MaxwellDupre approved these changes Feb 22, 2022
View reviewed changes

@MaxwellDupre MaxwellDupre left a comment

Copy link
Copy Markdown
Contributor

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.

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 the get() you need to use a blank key ''.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting core review and removed awaiting review labels Feb 22, 2022
@github-actions

github-actions Bot commented Mar 25, 2022

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Mar 25, 2022
@ChristianSi

ChristianSi commented Jul 1, 2022

Copy link
Copy Markdown

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

arhadthedev, rwoloszyn, and j-karls reacted with thumbs up emoji
All reactions
  • 👍 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@arhadthedev

arhadthedev commented Jul 1, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@arhadthedev

arhadthedev commented Jul 1, 2022

Copy link
Copy Markdown
Member

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

hiarcs reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jul 2, 2022
@ezio-melotti ezio-melotti removed the CLA signed label Jul 13, 2022
@ChristianSi

ChristianSi commented Aug 2, 2022

Copy link
Copy Markdown

Any news on this one?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Sep 2, 2022

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Sep 2, 2022
@ChristianSi

ChristianSi commented Sep 20, 2022

Copy link
Copy Markdown

@pslacerda It seems this PR got stalled because you didn't address the proposal 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!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 9, 2023
@arhadthedev
Merge branch 'main' into fix-issue-issue22253
394b83f
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Apr 10, 2023
@ChristianSi

ChristianSi commented Apr 10, 2023

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented May 11, 2023

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label May 11, 2023
@arhadthedev arhadthedev changed the title bpo-22253: Add support to unnamed sections in ConfigParser gh-66449: Add support to unnamed sections in ConfigParser May 11, 2023
@arhadthedev
Merge branch 'main' into fix-issue-issue22253
fa3f10b
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label May 12, 2023
@ChristianSi

This comment was marked as abuse.

Sign in to view
@arhadthedev

arhadthedev commented May 13, 2023

Copy link
Copy Markdown
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. From https://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
All reactions
  • 👎 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

furkanonder
furkanonder reviewed May 17, 2023
View reviewed changes
Comment thread Lib/configparser.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Jun 17, 2023

Copy link
Copy Markdown

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

ptman and j-karls reacted with confused emoji
All reactions
  • 😕 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Jun 17, 2023
@furkanonder furkanonder added stdlib Standard Library Python modules in the Lib/ directory stale Stale PR or inactive for long period of time. and removed stale Stale PR or inactive for long period of time. labels Aug 6, 2023
@Delgan Delgan mentioned this pull request Nov 4, 2023
Add support for "global" properties (before any section)? pyscaffold/configupdater#123
Closed
vadmium
vadmium reviewed Mar 24, 2024
View reviewed changes

@vadmium vadmium left a comment

Copy link
Copy Markdown
Member

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.

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())

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/configparser.py
section proxies.

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

@vadmium vadmium Mar 24, 2024

Copy link
Copy Markdown
Member

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.

options without a section?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/configparser.py
return "<TOP_LEVEL>"

def __eq__(self, other):
return repr(self) == repr(other)

@vadmium vadmium Mar 24, 2024

Copy link
Copy Markdown
Member

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.

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Misc/NEWS.d/next/Library/2022-09-22-07-33-00.bpo-22253.jdo4573.rst
@@ -0,0 +1,4 @@
:class:`configparser.ConfigParser` now accepts unnamed sections before named
ones, if configured to do so.

@vadmium vadmium Mar 24, 2024

Copy link
Copy Markdown
Member

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.

“accepts an unnamed section before named ones” might be clearer

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/configparser.py

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

@vadmium vadmium Mar 24, 2024

Copy link
Copy Markdown
Member

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.

configparser.TOP_LEVEL?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/configparser.py
empty_lines_in_values=True, default_section='DEFAULT',
interpolation=<unset>, converters=<unset>):
interpolation=<unset>, converters=<unset>,
allow_unnamed_section=False):

@vadmium vadmium Mar 24, 2024

Copy link
Copy Markdown
Member

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.

allow_unnamed_section not implemented

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@pslacerda pslacerda Mar 26, 2024

Copy link
Copy Markdown
Contributor Author

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.

This seems ok.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/configparser.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Mar 24, 2024
@hw-claudio

hw-claudio commented Mar 26, 2024

Copy link
Copy Markdown

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
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kernc kernc mannequin mentioned this pull request May 11, 2023
ConfigParser does not handle files without sections #66449
Closed
@ChristianSi

ChristianSi commented Mar 26, 2024

Copy link
Copy Markdown

@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ChristianSi

ChristianSi commented Mar 26, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

@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 😢

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pslacerda

pslacerda commented Mar 26, 2024

Copy link
Copy Markdown
Contributor Author

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
All reactions
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pslacerda

pslacerda commented Mar 26, 2024

Copy link
Copy Markdown
Contributor Author

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

ChristianSi reacted with rocket emoji
All reactions
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ChristianSi

ChristianSi commented Mar 29, 2024

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pslacerda @furkanonder
Update Lib/configparser.py
fdb7081
Co-authored-by: Furkan Onder <[email protected]>
@pslacerda

pslacerda commented Mar 29, 2024

Copy link
Copy Markdown
Contributor Author

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

#117273

drew-parsons reacted with hooray emoji ChristianSi reacted with rocket emoji
All reactions
  • 🎉 1 reaction
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pslacerda pslacerda closed this Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vadmium vadmium vadmium left review comments
@furkanonder furkanonder furkanonder left review comments
@csabella csabella csabella left review comments
+3 more reviewers
@MichalCab MichalCab MichalCab left review comments
@ChristianSi ChristianSi ChristianSi approved these changes
@MaxwellDupre MaxwellDupre MaxwellDupre approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting core review stdlib Standard Library Python modules in the Lib/ directory type-feature A feature request or enhancement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

19 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 @pslacerda1
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.