Skip to content

Commit 758a9c3

Browse files
miss-islingtonserhiy-storchakacsabella
authored
[3.15] gh-75595: Do not save a blank int entry in IDLE Settings (GH-152743) (#152827)
gh-75595: Do not save a blank int entry in IDLE Settings (GH-152743) 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. (cherry picked from commit 3428762) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Cheryl Sabella <cheryl.sabella@gmail.com>
1 parent 392f1cc commit 758a9c3

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

Lib/idlelib/configdialog.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2265,7 +2265,11 @@ def make_callback(var, config):
22652265
"Return default callback function to add values to changes instance."
22662266
def default_callback(*params):
22672267
"Add config values to changes instance."
2268-
changes.add_option(*config, var.get())
2268+
value = var.get()
2269+
# A blanked int entry is an empty string; do not save it as an
2270+
# invalid config value (gh-83653).
2271+
if value != '':
2272+
changes.add_option(*config, value)
22692273
return default_callback
22702274

22712275
def attach(self):

Lib/idlelib/idle_test/test_configdialog.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,17 @@ def test_make_callback(self):
15441544
self.assertEqual(changes['main']['section']['option'], '42')
15451545
changes.clear()
15461546

1547+
# gh-83653: a blank int entry is not saved as bad config data.
1548+
sv = StringVar(root)
1549+
cb = self.tracers.make_callback(sv, ('main', 'section', 'option'))
1550+
sv.set('')
1551+
cb()
1552+
self.assertNotIn('section', changes['main'])
1553+
sv.set('5')
1554+
cb()
1555+
self.assertEqual(changes['main']['section']['option'], '5')
1556+
changes.clear()
1557+
15471558
def test_attach_detach(self):
15481559
tr = self.tracers
15491560
iv = tr.add(self.iv, self.var_changed_increment)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Blanking an integer entry in IDLE's Settings dialog, such as "Auto squeeze
2+
min lines", no longer saves an empty string as an invalid configuration
3+
value.

0 commit comments

Comments
 (0)