summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorŁukasz Langa <lukasz@langa.pl>2013-01-01 21:33:19 (GMT)
committerŁukasz Langa <lukasz@langa.pl>2013-01-01 21:33:19 (GMT)
commita821f82f66260601aa184d5788226dd0c64251a0 (patch)
tree70e366f6ec7c3f6ee28aeceea8b5a1e728901a47 /Lib
parenteb6aa5c52597a1b7d67197ff094f7548728393f0 (diff)
downloadcpython-a821f82f66260601aa184d5788226dd0c64251a0.zip
cpython-a821f82f66260601aa184d5788226dd0c64251a0.tar.gz
cpython-a821f82f66260601aa184d5788226dd0c64251a0.tar.bz2
configparser: preserve section order when using `__setitem__` (issue #16820)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/configparser.py4
-rw-r--r--Lib/test/test_configparser.py4
2 files changed, 6 insertions, 2 deletions
diff --git a/Lib/configparser.py b/Lib/configparser.py
index eac508e..c7bee6b 100644
--- a/Lib/configparser.py
+++ b/Lib/configparser.py
@@ -962,8 +962,8 @@ class RawConfigParser(MutableMapping):
# no update method in configparser is atomic in this implementation.
if key == self.default_section:
self._defaults.clear()
- else:
- self.remove_section(key)
+ elif key in self._sections:
+ self._sections[key].clear()
self.read_dict({key: value})
def __delitem__(self, key):
diff --git a/Lib/test/test_configparser.py b/Lib/test/test_configparser.py
index 3823641..57e9df1 100644
--- a/Lib/test/test_configparser.py
+++ b/Lib/test/test_configparser.py
@@ -812,18 +812,22 @@ boolean {0[0]} NO
self.assertEqual(cf['section1']['name1'], 'value1')
self.assertEqual(cf['section2']['name2'], 'value2')
self.assertEqual(cf['section3']['name3'], 'value3')
+ self.assertEqual(cf.sections(), ['section1', 'section2', 'section3'])
cf['section2'] = {'name22': 'value22'}
self.assertEqual(set(cf['section2'].keys()), {'name22', 'named'})
self.assertEqual(cf['section2']['name22'], 'value22')
self.assertNotIn('name2', cf['section2'])
+ self.assertEqual(cf.sections(), ['section1', 'section2', 'section3'])
cf['section3'] = {}
self.assertEqual(set(cf['section3'].keys()), {'named'})
self.assertNotIn('name3', cf['section3'])
+ self.assertEqual(cf.sections(), ['section1', 'section2', 'section3'])
cf[self.default_section] = {}
self.assertEqual(set(cf[self.default_section].keys()), set())
self.assertEqual(set(cf['section1'].keys()), {'name1'})
self.assertEqual(set(cf['section2'].keys()), {'name22'})
self.assertEqual(set(cf['section3'].keys()), set())
+ self.assertEqual(cf.sections(), ['section1', 'section2', 'section3'])
class StrictTestCase(BasicTestCase):