From 5f6a8d9b1e8ecb05f79e57136e1f0b89758edffb Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 22 Sep 2026 22:20:25 +0300 Subject: [PATCH] gh-75487: Do not save a truncated number when an int entry is blanked in IDLE Settings (GH-157680) The value is recorded on every keystroke, so blanking "80" with the Backspace key left "8" to be saved. Blanking an entry now forgets the recorded value, so that the saved value is kept. (cherry picked from commit f67c51fb6077f759b048727cf367fdb2c88d3a19) Co-authored-by: Serhiy Storchaka --- Lib/idlelib/configdialog.py | 7 +++++-- Lib/idlelib/idle_test/test_configdialog.py | 4 ++++ .../IDLE/2026-09-17-17-00-00.gh-issue-75487.blankint.rst | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/IDLE/2026-09-17-17-00-00.gh-issue-75487.blankint.rst diff --git a/Lib/idlelib/configdialog.py b/Lib/idlelib/configdialog.py index 4c94d9be69e95e..603299d8f7ab7d 100644 --- a/Lib/idlelib/configdialog.py +++ b/Lib/idlelib/configdialog.py @@ -2266,10 +2266,13 @@ def make_callback(var, config): def default_callback(*params): "Add config values to changes instance." 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) + else: + # A blanked int entry: do not save an invalid value, and + # forget the value recorded while editing (gh-75487). + config_type, section, item = config + changes[config_type].get(section, {}).pop(item, None) return default_callback def attach(self): diff --git a/Lib/idlelib/idle_test/test_configdialog.py b/Lib/idlelib/idle_test/test_configdialog.py index a63fdfeec2f723..dc2ee2a68bdb36 100644 --- a/Lib/idlelib/idle_test/test_configdialog.py +++ b/Lib/idlelib/idle_test/test_configdialog.py @@ -1678,6 +1678,10 @@ def test_make_callback(self): sv.set('5') cb() self.assertEqual(changes['main']['section']['option'], '5') + # gh-75487: blanking the entry forgets the value recorded before. + sv.set('') + cb() + self.assertNotIn('option', changes['main']['section']) changes.clear() def test_attach_detach(self): diff --git a/Misc/NEWS.d/next/IDLE/2026-09-17-17-00-00.gh-issue-75487.blankint.rst b/Misc/NEWS.d/next/IDLE/2026-09-17-17-00-00.gh-issue-75487.blankint.rst new file mode 100644 index 00000000000000..5ae2d360f5c6a9 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2026-09-17-17-00-00.gh-issue-75487.blankint.rst @@ -0,0 +1,2 @@ +Fix saving a truncated number when an integer entry in the IDLE Settings +dialog is blanked with the Backspace key.