gh-89360: Fix ValueError in IDLE MultiCall event_delete (#152738)

Deleting a key binding for a sequence not bound to the virtual event no
longer raises a ValueError; the discrepancy is now ignored.
This commit is contained in:
Serhiy Storchaka
2026-07-01 19:22:03 +03:00
committed by GitHub
parent ef27e5b310
commit ea7619faea
3 changed files with 21 additions and 1 deletions
+16
View File
@@ -43,6 +43,22 @@ class MultiCallTest(unittest.TestCase):
mctext = self.mc(self.root)
self.assertIs(mctext.yview.__func__, Text.yview)
def test_event_delete_unbound_sequence(self):
# gh-89360: deleting a sequence that was not added to a virtual
# event is ignored instead of raising ValueError.
mctext = self.mc(self.root)
mctext.event_add('<<tester>>', '<Control-Key-a>')
info = mctext.event_info('<<tester>>')
self.assertEqual(len(info), 1)
# A different sequence, never added: a no-op, not an error.
mctext.event_delete('<<tester>>', '<Control-Key-b>')
self.assertEqual(mctext.event_info('<<tester>>'), info)
# The added sequence can still be deleted normally.
mctext.event_delete('<<tester>>', '<Control-Key-a>')
self.assertNotIn(info[0], mctext.event_info('<<tester>>'))
if __name__ == '__main__':
unittest.main(verbosity=2)
+2 -1
View File
@@ -386,10 +386,11 @@ def MultiCallCreator(widget):
if triplet is None:
#print("Tkinter event_delete: %s" % seq, file=sys.__stderr__)
widget.event_delete(self, virtual, seq)
else:
elif triplet in triplets:
if func is not None:
self.__binders[triplet[1]].unbind(triplet, func)
triplets.remove(triplet)
# Else the sequence is not bound; ignore it (gh-89360).
def event_info(self, virtual=None):
if virtual is None or virtual not in self.__eventinfo:
@@ -0,0 +1,3 @@
Fix a rare crash in the IDLE editor when the completion window is closed:
deleting a key binding for a sequence that is not bound to the virtual
event is now ignored instead of raising a ``ValueError``.