]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-75595: Do not save a blank int entry in IDLE Settings (#152743)
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 1 Jul 2026 21:57:47 +0000 (00:57 +0300)
committerGitHub <noreply@github.com>
Wed, 1 Jul 2026 21:57:47 +0000 (17:57 -0400)
gh-83653: Do not save a blank int entry in IDLE Settings

Blanking an integer entry wrote an empty string to the config file, which
caused an "invalid int value" warning when it was read back.

Co-authored-by: Cheryl Sabella <cheryl.sabella@gmail.com>
Lib/idlelib/configdialog.py
Lib/idlelib/idle_test/test_configdialog.py
Misc/NEWS.d/next/IDLE/2026-07-01-18-00-00.gh-issue-83653.cFgInt.rst [new file with mode: 0644]

index 10bd3c23450821410861c7a58b7ad3788f1e61db..4c94d9be69e95e15b00cc7c1f96d7998976700e5 100644 (file)
@@ -2265,7 +2265,11 @@ class VarTrace:
         "Return default callback function to add values to changes instance."
         def default_callback(*params):
             "Add config values to changes instance."
-            changes.add_option(*config, var.get())
+            value = var.get()
+            # A blanked int entry is an empty string; do not save it as an
+            # invalid config value (gh-83653).
+            if value != '':
+                changes.add_option(*config, value)
         return default_callback
 
     def attach(self):
index 2773ed7ce614b55097c2d3811b902c145074da24..c68fd304ea4235eba9ca70f0e81a40ab19e3aac9 100644 (file)
@@ -1544,6 +1544,17 @@ class VarTraceTest(unittest.TestCase):
         self.assertEqual(changes['main']['section']['option'], '42')
         changes.clear()
 
+        # gh-83653: a blank int entry is not saved as bad config data.
+        sv = StringVar(root)
+        cb = self.tracers.make_callback(sv, ('main', 'section', 'option'))
+        sv.set('')
+        cb()
+        self.assertNotIn('section', changes['main'])
+        sv.set('5')
+        cb()
+        self.assertEqual(changes['main']['section']['option'], '5')
+        changes.clear()
+
     def test_attach_detach(self):
         tr = self.tracers
         iv = tr.add(self.iv, self.var_changed_increment)
diff --git a/Misc/NEWS.d/next/IDLE/2026-07-01-18-00-00.gh-issue-83653.cFgInt.rst b/Misc/NEWS.d/next/IDLE/2026-07-01-18-00-00.gh-issue-83653.cFgInt.rst
new file mode 100644 (file)
index 0000000..5812b2d
--- /dev/null
@@ -0,0 +1,3 @@
+Blanking an integer entry in IDLE's Settings dialog, such as "Auto squeeze
+min lines", no longer saves an empty string as an invalid configuration
+value.