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.
This commit is contained in:
parent
25038ecfb6
commit
1d4a733cce
|
@ -846,6 +846,7 @@ class RawConfigParser(MutableMapping):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if section != self.default_section:
|
if section != self.default_section:
|
||||||
raise NoSectionError(section)
|
raise NoSectionError(section)
|
||||||
|
orig_keys = list(d.keys())
|
||||||
# Update with the entry specific variables
|
# Update with the entry specific variables
|
||||||
if vars:
|
if vars:
|
||||||
for key, value in vars.items():
|
for key, value in vars.items():
|
||||||
|
@ -854,7 +855,7 @@ class RawConfigParser(MutableMapping):
|
||||||
section, option, d[option], d)
|
section, option, d[option], d)
|
||||||
if raw:
|
if raw:
|
||||||
value_getter = lambda option: d[option]
|
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):
|
def popitem(self):
|
||||||
"""Remove a section from the parser and return it as
|
"""Remove a section from the parser and return it as
|
||||||
|
|
|
@ -915,8 +915,7 @@ class ConfigParserTestCase(BasicTestCase, unittest.TestCase):
|
||||||
self.check_items_config([('default', '<default>'),
|
self.check_items_config([('default', '<default>'),
|
||||||
('getdefault', '|<default>|'),
|
('getdefault', '|<default>|'),
|
||||||
('key', '|value|'),
|
('key', '|value|'),
|
||||||
('name', 'value'),
|
('name', 'value')])
|
||||||
('value', 'value')])
|
|
||||||
|
|
||||||
def test_safe_interpolation(self):
|
def test_safe_interpolation(self):
|
||||||
# See http://www.python.org/sf/511737
|
# See http://www.python.org/sf/511737
|
||||||
|
@ -1093,8 +1092,7 @@ class RawConfigParserTestCase(BasicTestCase, unittest.TestCase):
|
||||||
self.check_items_config([('default', '<default>'),
|
self.check_items_config([('default', '<default>'),
|
||||||
('getdefault', '|%(default)s|'),
|
('getdefault', '|%(default)s|'),
|
||||||
('key', '|%(name)s|'),
|
('key', '|%(name)s|'),
|
||||||
('name', '%(value)s'),
|
('name', '%(value)s')])
|
||||||
('value', 'value')])
|
|
||||||
|
|
||||||
def test_set_nonstring_types(self):
|
def test_set_nonstring_types(self):
|
||||||
cf = self.newconfig()
|
cf = self.newconfig()
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
`ConfigParser.items()` was fixed so that key-value pairs passed in via `vars`
|
||||||
|
are not included in the resulting output.
|
Loading…
Reference in New Issue