homepage

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: ConfigParser.getboolean fails on boolean options
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: lukasz.langa Nosy List: andreas-h, lukasz.langa, r.david.murray
Priority: normal Keywords:

Created on 2015年06月22日 16:45 by andreas-h, last changed 2022年04月11日 14:58 by admin. This issue is now closed.

Messages (3)
msg245638 - (view) Author: Andreas Hilboll (andreas-h) Date: 2015年06月22日 16:45
Not sure if this is by design (or if I'm doing something utterly stupid), but I often create a ConfigParser object for my application and then pass this around (or make it global).
So when I do something like
 cfg.set("input_filter", "include_filtered", True)
and then 
 cfg.getboolean("input_filter", "include_filtered")
I receive an error (AttributeError: 'bool' object has no attribute 'lower').
Wouldn't it be more sensible if getboolean would return the raw value in case the raw value is already a boolean?
If not, which would be the best way forward for me?
msg245639 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015年06月22日 17:05
In python3 you will get an error: "TypeError: option values must be strings". So, this is an infelicity in the configparser API. Or, rather, I presume it is a design decision (ie: python shouldn't guess what string format you want the value to have in the file).
I'll leave it up to Lukaz to decide if this should be closed, or if there is an acceptable feature request here. But your solution is to call str on your boolean values when you store them.
msg249793 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2015年09月04日 17:28
As R. David pointed out, this is fixed in Python 3 by emphasizing configparser is designed to hold strings at all times. Changing this would break lots of existing code out there. So, sadly, #wontfix.
Thank you for your report though. If you find the documentation is misleading, create a change for that and we'll submit it.
History
Date User Action Args
2022年04月11日 14:58:18adminsetgithub: 68676
2015年09月04日 17:28:49lukasz.langasetstatus: open -> closed
type: behavior
messages: + msg249793

resolution: wont fix
stage: resolved
2015年06月22日 17:05:33r.david.murraysetversions: + Python 3.6, - Python 2.7
nosy: + r.david.murray, lukasz.langa

messages: + msg245639

assignee: lukasz.langa
2015年06月22日 16:45:17andreas-hcreate

AltStyle によって変換されたページ (->オリジナル) /