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: Config parser don't raise DuplicateSectionError when reading
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: fdrake Nosy List: fdrake, johahn, tebeka
Priority: normal Keywords:

Created on 2003-10-26 12:20 by tebeka, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg18765 - (view) Author: Miki Tebeka (tebeka) * Date: 2003-10-26 12:20
According to the documentation of ConfigParser
"DuplicateSectionError" it is raised if multiple
sections with the same name are found.

In the code this is not the case (it continues to
update the section with the same name (see
ConfigParser.py line 447).

Either fix the code (which I prefer :-) of the
documentation.

Miki
msg18766 - (view) Author: Johan M. Hahn (johahn) Date: 2003-10-26 21:18
Logged In: YES 
user_id=887415

I hereby confirm the bug and I've included some sample code 
of it as well. Though I don't know which solution is the best. 
Fixing the code might break some production code that uses 
duplicate sections and it is therefor easier to just change the 
documentation. I also don't see reason to why they should be  
disallowed in the first place.

>>> import ConfigParser
>>> cp = ConfigParser.ConfigParser()
>>> from StringIO import StringIO
>>> fp = StringIO("""
;
[section1]
var1=option1
[section2]
var2=option2
[section1]
var3=option3
""")
>>> cp.readfp(fp)
>>> [x for x in cp.items('sec1')]
[('var1', 'option1'), ('var3', 'option3')]
>>> 

...johahn
msg18767 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2004-05-18 03:59
Logged In: YES 
user_id=3066

I've fixed the documentation; changing the semantics is too
invasive to existing applications.  ConfigParser doesn't
have enough internal state to know whether a section was
defined twice in a single input file or if it was defined in
two different files.  The later case should be  allowed,
while the former case is questionable at best.

Doc/lib/libcfgparser.tex 1.37
History
Date User Action Args
2022-04-11 14:56:00adminsetgithub: 39461
2003-10-26 12:20:31tebekacreate