configparser: preserve section order when using `__setitem__` (issue #16820)
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 @@
         # 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):