classification
Title: ConfigParser.set does not convert non-string values
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: Edwin.Pozharski, eric.araujo, r.david.murray
Priority: normal Keywords:

Created on 2010-06-02 21:01 by Edwin.Pozharski, last changed 2010-06-03 13:37 by Edwin.Pozharski. This issue is now closed.

Files
File name Uploaded Description Edit
unnamed Edwin.Pozharski, 2010-06-03 13:37
Messages (5)
msg106912 - (view) Author: Edwin Pozharski (Edwin.Pozharski) Date: 2010-06-02 21:01
set() method of ConfigParser accepts boolean True/False as values at runtime without converting them to strings internally.  As a result, getboolean() method reports the following error

  File "/usr/lib/python2.6/ConfigParser.py", line 350, in getboolean
    if v.lower() not in self._boolean_states:
AttributeError: 'bool' object has no attribute 'lower'

since it expects get() method to return strings.  (Same problem occurs if other types are used, int/float, etc)

Altering set() behavior may be not the best thing to do, I'd rather suggest that getboolean() converts the get() output to string.

Of course, the way to avoid this problem is always convert values submitted to set() to strings, but it's a hard-to-catch bug.  In my case, I was stuck with problematic configuration when assigning values to wx.CheckBox.GetValue(), which returns boolean.
msg106913 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-06-02 21:08
Would that mean that booleans would be converted to strings on set and converted back on get? Seems wasteful.

(I’ve changed the version field for this bug. Its meaning is not “versions this applies to” but “versions that will get a fix”, and 3.2 is the only active branch now. Some bugfixes may still go into 2.7.)
msg106918 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-06-02 21:33
Use SafeConfigParser instead, then you can't make the mistake of passing non-strings to set.

We really should update the docs so that ConfigParser is doced only in a 'deprecated' section.  But that's a different issue.  (Care to open it, merwok? :)
msg106944 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-06-03 11:50
See #8888
msg106950 - (view) Author: Edwin Pozharski (Edwin.Pozharski) Date: 2010-06-03 13:37
Thanks - gotta rtfm :)

On Wed, Jun 2, 2010 at 5:33 PM, R. David Murray <report@bugs.python.org>wrote:

>
> R. David Murray <rdmurray@bitdance.com> added the comment:
>
> Use SafeConfigParser instead, then you can't make the mistake of passing
> non-strings to set.
>
> We really should update the docs so that ConfigParser is doced only in a
> 'deprecated' section.  But that's a different issue.  (Care to open it,
> merwok? :)
>
> ----------
> nosy: +r.david.murray
> resolution:  -> wont fix
> stage:  -> committed/rejected
> status: open -> closed
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue8880>
> _______________________________________
>
History
Date User Action Args
2010-06-03 13:37:51Edwin.Pozharskisetfiles: + unnamed

messages: + msg106950
2010-06-03 11:50:20eric.araujosetmessages: + msg106944
2010-06-02 21:33:17r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg106918

resolution: wont fix
stage: resolved
2010-06-02 21:08:04eric.araujosetversions: + Python 3.2, - Python 2.6
nosy: + eric.araujo

messages: + msg106913

components: + Library (Lib)
2010-06-02 21:01:36Edwin.Pozharskicreate