[Python-checkins] r83226 - in python/branches/py3k: Doc/library/configparser.rst Lib/configparser.py

georg.brandl python-checkins at python.org
Thu Jul 29 16:17:12 CEST 2010


Author: georg.brandl
Date: Thu Jul 29 16:17:12 2010
New Revision: 83226

Log:
#1090076: explain the behavior of *vars* in get() better.

Modified:
   python/branches/py3k/Doc/library/configparser.rst
   python/branches/py3k/Lib/configparser.py

Modified: python/branches/py3k/Doc/library/configparser.rst
==============================================================================
--- python/branches/py3k/Doc/library/configparser.rst	(original)
+++ python/branches/py3k/Doc/library/configparser.rst	Thu Jul 29 16:17:12 2010
@@ -44,7 +44,7 @@
 On top of the core functionality, :class:`SafeConfigParser` supports
 interpolation.  This means values can contain format strings which refer to
 other values in the same section, or values in a special ``DEFAULT`` section.
-Additional defaults can be provided on initialization and retrieval.
+Additional defaults can be provided on initialization.
 
 For example::
 
@@ -92,8 +92,7 @@
 manner by both parsers.
 
 Default values can be specified by passing them as a dictionary when
-constructing the :class:`SafeConfigParser`.  Additional defaults may be passed
-to the :meth:`get` method which will override all others.
+constructing the :class:`SafeConfigParser`.
 
 Sections are normally stored in an :class:`collections.OrderedDict` which
 maintains the order of all keys.  An alternative dictionary type can be passed
@@ -418,10 +417,13 @@
 
 .. method:: ConfigParser.get(section, option, raw=False, vars=None)
 
-   Get an *option* value for the named *section*.  All the ``'%'``
-   interpolations are expanded in the return values, based on the defaults
-   passed into the :meth:`__init__` method, as well as the options *vars*
-   provided, unless the *raw* argument is true.
+   Get an *option* value for the named *section*.  If *vars* is provided, it
+   must be a dictionary.  The *option* is looked up in *vars* (if provided),
+   *section*, and in *defaults* in that order.
+
+   All the ``'%'`` interpolations are expanded in the return values, unless the
+   *raw* argument is true.  Values for interpolation keys are looked up in the
+   same manner as the option.
 
 
 .. method:: ConfigParser.items(section, raw=False, vars=None)

Modified: python/branches/py3k/Lib/configparser.py
==============================================================================
--- python/branches/py3k/Lib/configparser.py	(original)
+++ python/branches/py3k/Lib/configparser.py	Thu Jul 29 16:17:12 2010
@@ -661,11 +661,12 @@
     def get(self, section, option, raw=False, vars=None):
         """Get an option value for a given section.
 
-        All % interpolations are expanded in the return values, based on the
-        defaults passed into the constructor, unless the optional argument
-        `raw' is true.  Additional substitutions may be provided using the
-        `vars' argument, which must be a dictionary whose contents overrides
-        any pre-existing defaults.
+        If `vars' is provided, it must be a dictionary. The option is looked up
+        in `vars' (if provided), `section', and in `defaults' in that order.
+
+        All % interpolations are expanded in the return values, unless the
+        optional argument `raw' is true.  Values for interpolation keys are
+        looked up in the same manner as the option.
 
         The section DEFAULT is special.
         """


More information about the Python-checkins mailing list