bpo-32108: Don't clear configparser values if key is assigned to itse… · python/cpython@33cd058 · GitHub
Skip to content

Commit 33cd058

Browse files
csabellaambv
authored andcommitted
bpo-32108: Don't clear configparser values if key is assigned to itself (GH-7588)
1 parent c3f55be commit 33cd058

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

Lib/configparser.py

Lines changed: 2 additions & 1 deletion

Lib/test/test_configparser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,12 +850,18 @@ def test_setitem(self):
850850
self.assertEqual(set(cf['section3'].keys()), {'named'})
851851
self.assertNotIn('name3', cf['section3'])
852852
self.assertEqual(cf.sections(), ['section1', 'section2', 'section3'])
853+
# For bpo-32108, assigning default_section to itself.
854+
cf[self.default_section] = cf[self.default_section]
855+
self.assertNotEqual(set(cf[self.default_section].keys()), set())
853856
cf[self.default_section] = {}
854857
self.assertEqual(set(cf[self.default_section].keys()), set())
855858
self.assertEqual(set(cf['section1'].keys()), {'name1'})
856859
self.assertEqual(set(cf['section2'].keys()), {'name22'})
857860
self.assertEqual(set(cf['section3'].keys()), set())
858861
self.assertEqual(cf.sections(), ['section1', 'section2', 'section3'])
862+
# For bpo-32108, assigning section to itself.
863+
cf['section2'] = cf['section2']
864+
self.assertEqual(set(cf['section2'].keys()), {'name22'})
859865

860866
def test_invalid_multiline_value(self):
861867
if self.allow_no_value:
Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)