From a057deec917a1b3ec216ef413667ca314d216e00 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 a5d1aaeb5a946f..02133ce022d79e 100644 --- a/Lib/idlelib/configdialog.py +++ b/Lib/idlelib/configdialog.py @@ -2285,10 +2285,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 12927bee8d31fb..0d2a1747275e65 100644 --- a/Lib/idlelib/idle_test/test_configdialog.py +++ b/Lib/idlelib/idle_test/test_configdialog.py @@ -1712,6 +1712,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.