mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
bpo-32108: Don't clear configparser values if key is assigned to itself (GH-7588)
This commit is contained in:
parent
c3f55be7dd
commit
33cd058f21
3 changed files with 9 additions and 1 deletions
|
@ -963,7 +963,8 @@ class RawConfigParser(MutableMapping):
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
# To conform with the mapping protocol, overwrites existing values in
|
# To conform with the mapping protocol, overwrites existing values in
|
||||||
# the section.
|
# the section.
|
||||||
|
if key in self and self[key] is value:
|
||||||
|
return
|
||||||
# XXX this is not atomic if read_dict fails at any point. Then again,
|
# XXX this is not atomic if read_dict fails at any point. Then again,
|
||||||
# no update method in configparser is atomic in this implementation.
|
# no update method in configparser is atomic in this implementation.
|
||||||
if key == self.default_section:
|
if key == self.default_section:
|
||||||
|
|
|
@ -850,12 +850,18 @@ boolean {0[0]} NO
|
||||||
self.assertEqual(set(cf['section3'].keys()), {'named'})
|
self.assertEqual(set(cf['section3'].keys()), {'named'})
|
||||||
self.assertNotIn('name3', cf['section3'])
|
self.assertNotIn('name3', cf['section3'])
|
||||||
self.assertEqual(cf.sections(), ['section1', 'section2', 'section3'])
|
self.assertEqual(cf.sections(), ['section1', 'section2', 'section3'])
|
||||||
|
# For bpo-32108, assigning default_section to itself.
|
||||||
|
cf[self.default_section] = cf[self.default_section]
|
||||||
|
self.assertNotEqual(set(cf[self.default_section].keys()), set())
|
||||||
cf[self.default_section] = {}
|
cf[self.default_section] = {}
|
||||||
self.assertEqual(set(cf[self.default_section].keys()), set())
|
self.assertEqual(set(cf[self.default_section].keys()), set())
|
||||||
self.assertEqual(set(cf['section1'].keys()), {'name1'})
|
self.assertEqual(set(cf['section1'].keys()), {'name1'})
|
||||||
self.assertEqual(set(cf['section2'].keys()), {'name22'})
|
self.assertEqual(set(cf['section2'].keys()), {'name22'})
|
||||||
self.assertEqual(set(cf['section3'].keys()), set())
|
self.assertEqual(set(cf['section3'].keys()), set())
|
||||||
self.assertEqual(cf.sections(), ['section1', 'section2', 'section3'])
|
self.assertEqual(cf.sections(), ['section1', 'section2', 'section3'])
|
||||||
|
# For bpo-32108, assigning section to itself.
|
||||||
|
cf['section2'] = cf['section2']
|
||||||
|
self.assertEqual(set(cf['section2'].keys()), {'name22'})
|
||||||
|
|
||||||
def test_invalid_multiline_value(self):
|
def test_invalid_multiline_value(self):
|
||||||
if self.allow_no_value:
|
if self.allow_no_value:
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
In configparser, don't clear section when it is assigned to itself.
|
Loading…
Add table
Add a link
Reference in a new issue