homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: document ConfigParser behaviour when a file has same section multiple times
Type: behavior Stage: resolved
Components: Documentation, Library (Lib) Versions: Python 3.0
process
Status: closed Resolution: duplicate
Dependencies: Superseder: configparser support for reading from strings and dictionaries
View: 9452
Assigned To: docs@python Nosy List: BreamoreBoy, docs@python, draghuram, georg.brandl, honesthacker, lukasz.langa, orsenthil, trash80, ygingras
Priority: normal Keywords: easy, patch

Created on 2008年02月28日 22:11 by draghuram, last changed 2022年04月11日 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
no-dups-configparser.diff ygingras, 2009年02月04日 17:43 Patch for throwing an exception
Messages (9)
msg63109 - (view) Author: Raghuram Devarakonda (draghuram) (Python triager) Date: 2008年02月28日 22:11
ConfigParser.add_section() raises DuplicateSectionError if add_section()
is called with the name of a section that is already present. How ever,
if a section is present multiple times in a file, readfp() does not
raise any exception. Instead, the sections are "combined" with values in
latter sections overwriting previous values (if any). This should be
documented in readfp(). I tried few alternatives but the sentences don't
look right. I am creating the issue in the hope that some one else may
give it a try while I continue to come up with a doc patch.
msg63110 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2008年02月28日 22:31
Should this 'undesirable' behavior be documented? My thoughts are
a) All the key,value pairs in the named section be retrived from entire
file. Just appending the dict.
Otherwise, 
b) An Exception can be thrown if it encounters an invalid Configfile
having multiple same sections which can cause problem, but I cannot
readily think of one such case.
What do others think?
Thanks,
Senthil
msg63139 - (view) Author: Raghuram Devarakonda (draghuram) (Python triager) Date: 2008年02月29日 15:47
> Should this 'undesirable' behavior be documented? My thoughts are
Document should definitely reflect the code whether the behaviour is
desirable or not.
> a) All the key,value pairs in the named section be retrived from entire
> file. Just appending the dict.
Isn't this what is happening now unless I am not following you?
> Otherwise,
> b) An Exception can be thrown if it encounters an invalid Configfile
> having multiple same sections which can cause problem, but I cannot
> readily think of one such case.
I have no problem with throwing an exception in case of duplicate
sections but I don't think that can be done by default (it may break
some programs).
msg81145 - (view) Author: Yannick Gingras (ygingras) * Date: 2009年02月04日 17:43
The attached patch is a proof of concept for throwing an exception.
As discussed on the mailing list [1], it has some shortcomings that
should be addressed before it is merged.
[1]: http://mail.python.org/pipermail/python-dev/2009- 
msg81594 - (view) Author: Raghuram Devarakonda (draghuram) (Python triager) Date: 2009年02月10日 20:02
> The attached patch is a proof of concept for throwing an exception.
If it is not too much of a problem, can you upload the patch to
http://codereview.appspot.com? Reviewing there is simpler. Also, you
will have to include some test cases in the patch.
> As discussed on the mailing list [1], it has some shortcomings that
> should be addressed before it is merged.
I think that the builder interface already has correct behaviour in
that duplicate sections are not allowed. So you can have
'unique_sections' control only parser interface and can set it to
False by default (to be compatible with current behaviour).
> [1]: http://mail.python.org/pipermail/python-dev/2009-
Correct discussion link:
http://mail.python.org/pipermail/python-dev/2009-February/085838.html 
msg92055 - (view) Author: trash80 (trash80) Date: 2009年08月29日 03:40
I am using configparser after combining 3 or so ini files, I would like
to merge similar sections rather than throwing an exception. Right now
I have to make sure the ini files all have unique sections, but I would
like to able to use same section names, then combine the files and have
the sections merged. Even merging the variables within sections would
be nice.
Throwing an exception, imho, is no the right direction. Even in same
name sections are in the same file, the variables where introduced for a
reason.
Or maybe a trigger option ie action=merge or action=flag.
msg111417 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2010年07月24日 02:17
I personally would keep the current behaviour so that:
- creating a duplicate section programatically invokes an error
- reading a file which has duplicate sections causes an implicit merge without any exceptions
This is quite understandable, more so when you consider how ConfigParser merges configuration from multiple sources as well.
Brett, the only thing I guess we could do here is to adjust the documentation so it's more clear on the default behaviour.
msg111527 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010年07月25日 08:58
@Łukasz: could you provide a patch that clarifies the default behaviour.
msg112698 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2010年08月03日 21:50
This bug is superseded by #9452 where the patch includes a `strict=` argument to __init__ which enables checking for section duplicates when reading from a single source.
History
Date User Action Args
2022年04月11日 14:56:31adminsetgithub: 46457
2010年08月03日 21:54:10eric.araujosetstatus: open -> closed
resolution: duplicate
superseder: configparser support for reading from strings and dictionaries
stage: needs patch -> resolved
2010年08月03日 21:50:00lukasz.langasetmessages: + msg112698
2010年07月25日 08:58:21BreamoreBoysetnosy: + BreamoreBoy, docs@python
messages: + msg111527

assignee: georg.brandl -> docs@python
stage: test needed -> needs patch
2010年07月24日 02:17:25lukasz.langasetnosy: + lukasz.langa
messages: + msg111417
2009年12月28日 19:19:27honesthackersetnosy: + honesthacker
2009年08月29日 03:40:57trash80setnosy: + trash80

messages: + msg92055
versions: + Python 3.0, - Python 2.6
2009年04月22日 18:50:04ajaksu2setpriority: normal
keywords: + easy
components: + Library (Lib)
stage: test needed
2009年02月10日 20:02:53draghuramsetmessages: + msg81594
2009年02月04日 17:43:56ygingrassetfiles: + no-dups-configparser.diff
nosy: + ygingras
messages: + msg81145
keywords: + patch
2008年02月29日 15:47:54draghuramsetmessages: + msg63139
2008年02月28日 22:31:36orsenthilsetnosy: + orsenthil
messages: + msg63110
2008年02月28日 22:11:59draghuramcreate

AltStyle によって変換されたページ (->オリジナル) /