[ python-Feature Requests-974019 ] ConfigParser non-string defaults
broken with .getboolean()
SourceForge.net
noreply at sourceforge.net
Thu Jun 17 08:37:57 EDT 2004
Feature Requests item #974019, was opened at 2004-06-16 11:36
Message generated for change (Comment added) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=974019&group_id=5470
>Category: None
>Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Charles (melicertes)
Assigned to: Nobody/Anonymous (nobody)
Summary: ConfigParser non-string defaults broken with .getboolean()
Initial Comment:
ConfigParser.getboolean() fails if it falls back to a
default value, and the value passed in was a boolean
object (instead of a string) because it unconditionally
does v.lower().
This should be fixed; there's something un-Pythonic
about expecting a boolean value but not being able to
actually provide a boolean as the default.
I've attached a patch (against 2.3.4c1; should apply to
2.3.4, I think) which makes the v.lower() conditional
on v being a string, and adds bool(True), bool(False),
int(1), and int(0) to _boolean_states.
Alternative resolution: change the documentation to
specify that /only/ strings should be passed in the
defaults dictionary. Less Pythonic.
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2004-06-17 07:37
Message:
Logged In: YES
user_id=80475
The method is functioning exactly as documented.
Changing this to a feature request.
FWIW, it seems reasonable to allow a boolean to be passed in
a default; however, calling it unpythonic is a bit extreme
since the whole API is designed to work with text arguments.
My solution would be to just add two lines after the self.get:
if isinstance(v, bool):
return v
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=974019&group_id=5470
More information about the Python-bugs-list
mailing list