You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ConfigParser.set does not convert non-string values #53126
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2010-06-02.21:33:17.443>created_at=<Date2010-06-02.21:01:36.677>labels= ['type-bug', 'library']
title='ConfigParser.set does not convert non-string values'updated_at=<Date2010-06-03.13:37:51.855>user='https://bugs.python.org/EdwinPozharski'
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.
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.)
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? :)
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? :)
Activity
EdwinPozharski commentedon Jun 2, 2010
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.
merwok commentedon Jun 2, 2010
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.)
bitdancer commentedon Jun 2, 2010
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? :)
merwok commentedon Jun 3, 2010
See bpo-8888
EdwinPozharski commentedon Jun 3, 2010
Thanks - gotta rtfm :)
On Wed, Jun 2, 2010 at 5:33 PM, R. David Murray <[email protected]>wrote: