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.
Created on 2004年06月16日 16:36 by melicertes, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| ConfigParser.patch | melicertes, 2004年06月16日 16:36 | Patch to fix ConfigParser.getboolean() | ||
| Messages (5) | |||
|---|---|---|---|
| msg54180 - (view) | Author: Charles (melicertes) | Date: 2004年06月16日 16:36 | |
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. |
|||
| msg54181 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2004年06月17日 12:37 | |
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 |
|||
| msg54182 - (view) | Author: Anthony Baxter (anthonybaxter) (Python triager) | Date: 2004年08月09日 09:58 | |
Logged In: YES user_id=29957 I don't see any reason to not allow a boolean as a default. Raymond's solution seems like a good one to me. Anyone object? |
|||
| msg61964 - (view) | Author: Raghuram Devarakonda (draghuram) (Python triager) | Date: 2008年02月01日 16:32 | |
With the latest python, get() itself fails with boolean value default. I
tried with this script:
-------------
from ConfigParser import ConfigParser
cfg = ConfigParser({'var':True})
cfg.add_section('test_section')
print cfg.getboolean('test_section', 'var')
-------------
and it results in
-------------
Traceback (most recent call last):
File "t.py", line 4, in <module>
print cfg.getboolean('test_section', 'var')
File "/localhome/raghu/localwork/cpython/trunk/Lib/ConfigParser.py",
line 349, in getboolean
v = self.get(section, option)
File "/localhome/raghu/localwork/cpython/trunk/Lib/ConfigParser.py",
line 545, in get
return self._interpolate(section, option, value, d)
File "/localhome/raghu/localwork/cpython/trunk/Lib/ConfigParser.py",
line 585, in _interpolate
if "%(" in value:
TypeError: argument of type 'bool' is not iterable
-------------
I doubt if it is worth fixing the OP's issue considering that
_interpolate is assuming the value to be string. Can I close this issue?
|
|||
| msg86300 - (view) | Author: Daniel Diniz (ajaksu2) * (Python triager) | Date: 2009年04月22日 15:21 | |
+1 for closing. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:04 | admin | set | github: 40408 |
| 2009年04月22日 17:12:56 | draghuram | set | status: open -> closed resolution: wont fix |
| 2009年04月22日 15:21:52 | ajaksu2 | set | priority: normal -> low nosy: + ajaksu2 messages: + msg86300 |
| 2009年02月14日 13:57:53 | ajaksu2 | set | keywords:
+ patch, easy stage: test needed versions: + Python 2.7, - Python 2.6 |
| 2008年02月01日 16:32:08 | draghuram | set | messages:
+ msg61964 components: + Library (Lib), - None versions: + Python 2.6 |
| 2008年02月01日 15:00:38 | draghuram | set | nosy: + draghuram |
| 2004年06月16日 16:36:16 | melicertes | create | |