configparser: preserve section order when using `__setitem__` (issue #16820)
diff --git a/Lib/configparser.py b/Lib/configparser.py
index 243efec..e5536a0 100644
--- a/Lib/configparser.py
+++ b/Lib/configparser.py
@@ -959,7 +959,8 @@
 
         # XXX this is not atomic if read_dict fails at any point. Then again,
         # no update method in configparser is atomic in this implementation.
-        self.remove_section(key)
+        if key in self._sections:
+            self._sections[key].clear()
         self.read_dict({key: value})
 
     def __delitem__(self, key):