diff options
author | Ćukasz Langa <lukasz@langa.pl> | 2017-08-24 16:43:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-24 16:43:53 (GMT) |
commit | a5fab17fc11433b2418f626dc51e8a3d07b198ca (patch) | |
tree | 173aeb5a7491a9bd0956fcbc2d5f8818a7f6fb41 /Lib/configparser.py | |
parent | a6296d34a478b4f697ea9db798146195075d496c (diff) | |
download | cpython-a5fab17fc11433b2418f626dc51e8a3d07b198ca.zip cpython-a5fab17fc11433b2418f626dc51e8a3d07b198ca.tar.gz cpython-a5fab17fc11433b2418f626dc51e8a3d07b198ca.tar.bz2 |
bpo-23835: Restore legacy defaults= behavior for RawConfigParser (#3191)
The fix for bpo-23835 fixed ConfigParser behavior in defaults= handling.
Unfortunately, it caused a backwards compatibility regression with
RawConfigParser objects which allow for non-string values.
This commit restores the legacy behavior for RawConfigParser only.
Diffstat (limited to 'Lib/configparser.py')
-rw-r--r-- | Lib/configparser.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Lib/configparser.py b/Lib/configparser.py index 3609240..e172ac8 100644 --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -635,7 +635,7 @@ class RawConfigParser(MutableMapping): if converters is not _UNSET: self._converters.update(converters) if defaults: - self.read_dict({default_section: defaults}) + self._read_defaults(defaults) def defaults(self): return self._defaults @@ -1121,6 +1121,12 @@ class RawConfigParser(MutableMapping): section, name, val) + def _read_defaults(self, defaults): + """Read the defaults passed in the initializer. + Note: values can be non-string.""" + for key, value in defaults.items(): + self._defaults[self.optionxform(key)] = value + def _handle_error(self, exc, fpname, lineno, line): if not exc: exc = ParsingError(fpname) @@ -1198,6 +1204,11 @@ class ConfigParser(RawConfigParser): self._validate_value_types(section=section) super().add_section(section) + def _read_defaults(self, defaults): + """Reads the defaults passed in the initializer, implicitly converting + values to strings like the rest of the API.""" + self.read_dict({self.default_section: defaults}) + class SafeConfigParser(ConfigParser): """ConfigParser alias for backwards compatibility purposes.""" |