Issue1090076
Created on 2004-12-22 22:23 by gagenellina, last changed 2008-02-04 17:27 by draghuram.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | Remove |
| cfgdoc.diff | draghuram, 2008-02-04 17:27 | |||
| Messages (5) | |||
|---|---|---|---|
| msg60620 - (view) | Author: Gabriel Genellina (gagenellina) | Date: 2004-12-22 22:23 | |
ConfigParser.get has an optional argument vars that -
according to the docstring- "which must be a dictionary
whose contents overrides any pre-existing defaults."
I understand that it overrides the default values, but
should not override an actual value existing in the file.
That is, given this contents:
[DEFAULT]
key1=default1
[section]
key2=value2
vars={'key1:vars1','key2:vars2'}
cfg.get('section','key1',0,vars) gives 'vars1' (ok)
cfg.get('section','key2',0,vars) gives 'vars2' (wrong,
should be 'value2', since key2 is actually in the section
and no default is needed).
To correct this behavior, simply move this two lines of
code up in ConfigParser.get (ConfigParser.py), just below
the first line and before the first try/except:
# Update with the entry specific variables
if vars is not None:
d.update(vars)
|
|||
| msg60621 - (view) | Author: Tony Meyer (anadelonbrin) | Date: 2005-01-31 00:42 | |
Logged In: YES user_id=552329 This is indeed what happens. However, changing this could break existing code, so an alternative fix would be to change the documentation to "overrides any pre-existing values.". I am not sure what the desired behaviour is - if it is what is current, then recommend updating the documentation. If the desired behaviour is what the documentation currently says, then recommend applying the above patch (although the code is not exactly the same anymore, the effect is). |
|||
| msg60622 - (view) | Author: Martin v. Löwis (loewis) | Date: 2005-03-03 10:21 | |
Logged In: YES user_id=21627 I believe the current behaviour is there ever since revision 1.6, when the vars parameter was first introduced. The commit message says date: 1999/01/26 19:29:25; author: guido; state: Exp; lines: +17 -6 Patch by Chris Petrilli (not really tested since I don't know this module myself) to accept an option keyword argument (vars) that is substituted on top of the defaults that were setup in __init__. The patch also fixes the problem where you can't have recusive references inside your configuration file. We might want to ask Petrilli what the intention of this feature was, or just proceed with changing the documentation (and docstrings); contributions in that direction are welcome. I agree with anadelonbrin that the proposed change is probably not adequate. |
|||
| msg61968 - (view) | Author: Raghuram Devarakonda (draghuram) | Date: 2008-02-01 17:53 | |
The following two statements from ConfigParser document clearly mention
that what is passed in 'vars' are defaults and defaults come into
picture only when values are not explicitly set.
"Default values can be specified by passing them into the ConfigParser
constructor as a dictionary. Additional defaults may be passed into the
get() method which will override all others."
"ConfigParser.get(section, option[, raw[, vars]])¶
Get an option value for the named section. All the '%'
interpolations are expanded in the return values, based on the defaults
passed into the constructor, as well as the options vars provided,
unless the raw argument is true."
If we can not change the behaviour (as it will break existing code), we
should explicitly document this fact. Basically, get() looks for options
in the following order:
1) in 'vars'.
2) in the actual section
3) in default section
|
|||
| msg62045 - (view) | Author: Raghuram Devarakonda (draghuram) | Date: 2008-02-04 17:27 | |
The patch "cfgdoc.diff" contains changes to rst as well as to the doc string. Can some one please review it? |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2008-02-04 17:27:40 | draghuram | set | files:
+ cfgdoc.diff messages: + msg62045 |
| 2008-02-01 17:54:36 | draghuram | set | components:
+ Documentation, - Library (Lib) versions: + Python 2.6, - Python 2.3 |
| 2008-02-01 17:53:12 | draghuram | set | nosy:
+ draghuram messages: + msg61968 |
| 2004-12-22 22:23:31 | gagenellina | create | |