Skip to content

Commit 1d4a733

Browse files
chrBrdambv
authored andcommitted
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.
1 parent 25038ec commit 1d4a733

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

Lib/configparser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ def items(self, section=_UNSET, raw=False, vars=None):
846846
except KeyError:
847847
if section != self.default_section:
848848
raise NoSectionError(section)
849+
orig_keys = list(d.keys())
849850
# Update with the entry specific variables
850851
if vars:
851852
for key, value in vars.items():
@@ -854,7 +855,7 @@ def items(self, section=_UNSET, raw=False, vars=None):
854855
section, option, d[option], d)
855856
if raw:
856857
value_getter = lambda option: d[option]
857-
return [(option, value_getter(option)) for option in d.keys()]
858+
return [(option, value_getter(option)) for option in orig_keys]
858859

859860
def popitem(self):
860861
"""Remove a section from the parser and return it as

Lib/test/test_configparser.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -915,8 +915,7 @@ def test_items(self):
915915
self.check_items_config([('default', '<default>'),
916916
('getdefault', '|<default>|'),
917917
('key', '|value|'),
918-
('name', 'value'),
919-
('value', 'value')])
918+
('name', 'value')])
920919

921920
def test_safe_interpolation(self):
922921
# See http://www.python.org/sf/511737
@@ -1093,8 +1092,7 @@ def test_items(self):
10931092
self.check_items_config([('default', '<default>'),
10941093
('getdefault', '|%(default)s|'),
10951094
('key', '|%(name)s|'),
1096-
('name', '%(value)s'),
1097-
('value', 'value')])
1095+
('name', '%(value)s')])
10981096

10991097
def test_set_nonstring_types(self):
11001098
cf = self.newconfig()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`ConfigParser.items()` was fixed so that key-value pairs passed in via `vars`
2+
are not included in the resulting output.

0 commit comments

Comments
 (0)