Skip to content

Commit 1ad12c8

Browse files
gh-75487: Do not save a truncated number when an int entry is blanked in IDLE Settings
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.
1 parent 9ab004d commit 1ad12c8

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

Lib/idlelib/configdialog.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,10 +2266,13 @@ def make_callback(var, config):
22662266
def default_callback(*params):
22672267
"Add config values to changes instance."
22682268
value = var.get()
2269-
# A blanked int entry is an empty string; do not save it as an
2270-
# invalid config value (gh-83653).
22712269
if value != '':
22722270
changes.add_option(*config, value)
2271+
else:
2272+
# A blanked int entry: do not save an invalid value, and
2273+
# forget the value recorded while editing (gh-75487).
2274+
config_type, section, item = config
2275+
changes[config_type].get(section, {}).pop(item, None)
22732276
return default_callback
22742277

22752278
def attach(self):

Lib/idlelib/idle_test/test_configdialog.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,10 @@ def test_make_callback(self):
16781678
sv.set('5')
16791679
cb()
16801680
self.assertEqual(changes['main']['section']['option'], '5')
1681+
# gh-75487: blanking the entry forgets the value recorded before.
1682+
sv.set('')
1683+
cb()
1684+
self.assertNotIn('option', changes['main']['section'])
16811685
changes.clear()
16821686

16831687
def test_attach_detach(self):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix saving a truncated number when an integer entry in the IDLE Settings
2+
dialog is blanked with the Backspace key.

0 commit comments

Comments
 (0)