[Python-checkins] bpo-33251: Prevent ConfigParser.items returning items present in vars. (#6446)

Łukasz Langa webhook-mailer at python.org
Mon Apr 23 15:16:23 EDT 2018


https://github.com/python/cpython/commit/1d4a733cceee237f0850b7887c2945dee707da27
commit: 1d4a733cceee237f0850b7887c2945dee707da27
branch: master
author: Chris Bradbury <chris at binaryspanner.com>
committer: Łukasz Langa <lukasz at langa.pl>
date: 2018年04月23日T12:16:17-07:00
summary:
bpo-33251: Prevent ConfigParser.items returning items present in vars. (#6446)
* bpo-33251: ConfigParser.items no longer returns items present in vars.
Documentation for `ConfigParser.items()` states:
'Items present in vars no longer appear in the result.'
This fix aligns behaviour to that specified in the documentation.
files:
A Misc/NEWS.d/next/Library/2018-04-23-18-25-36.bpo-33251.C_K-J9.rst
M Lib/configparser.py
M Lib/test/test_configparser.py
diff --git a/Lib/configparser.py b/Lib/configparser.py
index 33dc9b9046f1..a681d3990e72 100644
--- a/Lib/configparser.py
+++ b/Lib/configparser.py
@@ -846,6 +846,7 @@ def items(self, section=_UNSET, raw=False, vars=None):
 except KeyError:
 if section != self.default_section:
 raise NoSectionError(section)
+ orig_keys = list(d.keys())
 # Update with the entry specific variables
 if vars:
 for key, value in vars.items():
@@ -854,7 +855,7 @@ def items(self, section=_UNSET, raw=False, vars=None):
 section, option, d[option], d)
 if raw:
 value_getter = lambda option: d[option]
- return [(option, value_getter(option)) for option in d.keys()]
+ return [(option, value_getter(option)) for option in orig_keys]
 
 def popitem(self):
 """Remove a section from the parser and return it as
diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py
index 4d07203b9dac..87b811f09b6e 100644
--- a/Lib/test/test_configparser.py
+++ b/Lib/test/test_configparser.py
@@ -915,8 +915,7 @@ def test_items(self):
 self.check_items_config([('default', '<default>'),
 ('getdefault', '|<default>|'),
 ('key', '|value|'),
- ('name', 'value'),
- ('value', 'value')])
+ ('name', 'value')])
 
 def test_safe_interpolation(self):
 # See http://www.python.org/sf/511737
@@ -1093,8 +1092,7 @@ def test_items(self):
 self.check_items_config([('default', '<default>'),
 ('getdefault', '|%(default)s|'),
 ('key', '|%(name)s|'),
- ('name', '%(value)s'),
- ('value', 'value')])
+ ('name', '%(value)s')])
 
 def test_set_nonstring_types(self):
 cf = self.newconfig()
diff --git a/Misc/NEWS.d/next/Library/2018-04-23-18-25-36.bpo-33251.C_K-J9.rst b/Misc/NEWS.d/next/Library/2018-04-23-18-25-36.bpo-33251.C_K-J9.rst
new file mode 100644
index 000000000000..fc6861f0d368
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-04-23-18-25-36.bpo-33251.C_K-J9.rst
@@ -0,0 +1,2 @@
+`ConfigParser.items()` was fixed so that key-value pairs passed in via `vars`
+are not included in the resulting output.


More information about the Python-checkins mailing list

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