[issue16820] configparser.ConfigParser.clean and .update bugs

2012-12-30 Thread Wolfgang Scherer

New submission from Wolfgang Scherer:

configparser.ConfigParser.clean() always fails:

>>> cfg = configparser.ConfigParser()
>>> if not hasattr(configparser.ConfigParser, 'clear'):
... configparser.ConfigParser.clear = configparser_clear_compat
>>> cfg.clear() #doctest: +ELLIPSIS
Traceback (most recent call last):
...
ValueError: Cannot remove the default section.

configparser.ConfigParser.update() overwrites all sections except DEFAULT 
instead of updating them.

See attached test file-

--
components: Library (Lib)
files: bug_configparser.py
messages: 178588
nosy: wolfmanx
priority: normal
severity: normal
status: open
title: configparser.ConfigParser.clean and .update bugs
type: behavior
versions: Python 3.2
Added file: http://bugs.python.org/file28493/bug_configparser.py

___
Python tracker 
<http://bugs.python.org/issue16820>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16820] configparser.ConfigParser.clean and .update bugs

2012-12-31 Thread Wolfgang Scherer

Wolfgang Scherer added the comment:

Thanks, works for me.

I only noted the discrepancy and did not give it much thought.
I will just implement a merge method on top of read_dict.
That gives me all options that could be desired :).

However, after implementing the entire compatibility layer, I found one more 
issue:

Using self.remove_section() changes the section order during an update.
I would prefer that the section be cleared instead of removed in order to 
preserve the section order. Since OrderedDict does indeed preserve the key 
order during update, I think that this does not violate the Mapping Protocol.

If this is not desired, just go ahead and close the issue.

See also attached example bug_configparser_update_order.py:

OrderedDict does not change the order of keys upon .update():

>>> od = OrderedDict((('section1', {}), ('section2', {})))

>>> list(od.keys())
['section1', 'section2']

>>> od.update((('section1', {}), ('section3', {})))

>>> list(od.keys())
['section1', 'section2', 'section3']

But ConfigParser changes the order of sections upon .update():

>>> cfg = configparser.ConfigParser()
>>> cfg.update((('section1', {}), ('section2', {})))

>>> cfg.sections()
['section1', 'section2']

>>> cfg.update((('section1', {}), ('section3', {})))

>>> cfg.sections()
['section2', 'section1', 'section3']

--
resolution: fixed -> rejected
status: closed -> open
Added file: http://bugs.python.org/file28514/bug_configparser_update_order.py

___
Python tracker 
<http://bugs.python.org/issue16820>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com