From b6d1989e315d950a79bf8403a90f2f3cc62ee630 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 16 Sep 2026 00:44:36 +0300 Subject: [PATCH] gh-60402: Fix Tab in a string in IDLE Open the file name completion list only if some file name starts with the text before the cursor; otherwise insert a tab. Co-authored-by: Roger Serwy Co-Authored-By: Claude Opus 5 (1M context) --- Lib/idlelib/autocomplete.py | 4 ++++ Lib/idlelib/idle_test/test_autocomplete.py | 6 ++++++ .../next/IDLE/2026-09-15-21-44-35.gh-issue-60402.iFz6X6.rst | 2 ++ 3 files changed, 12 insertions(+) create mode 100644 Misc/NEWS.d/next/IDLE/2026-09-15-21-44-35.gh-issue-60402.iFz6X6.rst diff --git a/Lib/idlelib/autocomplete.py b/Lib/idlelib/autocomplete.py index 032d31225315fb..9cb809bc7d4646 100644 --- a/Lib/idlelib/autocomplete.py +++ b/Lib/idlelib/autocomplete.py @@ -153,6 +153,10 @@ def open_completions(self, args): comp_lists = self.fetch_completions(comp_what, mode) if not comp_lists[0]: return None + if (complete and mode == FILES + and not any(name.startswith(comp_start) + for name in comp_lists[0])): + return None self.autocompletewindow = self._make_autocomplete_window() return not self.autocompletewindow.show_window( comp_lists, "insert-%dc" % len(comp_start), diff --git a/Lib/idlelib/idle_test/test_autocomplete.py b/Lib/idlelib/idle_test/test_autocomplete.py index 88af3efc35bbd1..9086c31d2733b6 100644 --- a/Lib/idlelib/idle_test/test_autocomplete.py +++ b/Lib/idlelib/idle_test/test_autocomplete.py @@ -218,6 +218,12 @@ def make_acw(): return self.dummy_acw() self.assertTrue(acp.open_completions(ac.TAB)) self.text.delete('1.0', 'end') + # No file name starts with the text (gh-60402). + self.text.insert('1.0', '"hello wor') + self.assertIsNone(acp.open_completions(ac.TAB)) + self.assertTrue(acp.open_completions(ac.FORCE)) + self.text.delete('1.0', 'end') + def test_completion_kwds(self): self.assertIn('and', ac.completion_kwds) self.assertIn('case', ac.completion_kwds) diff --git a/Misc/NEWS.d/next/IDLE/2026-09-15-21-44-35.gh-issue-60402.iFz6X6.rst b/Misc/NEWS.d/next/IDLE/2026-09-15-21-44-35.gh-issue-60402.iFz6X6.rst new file mode 100644 index 00000000000000..9b876ab0486f20 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2026-09-15-21-44-35.gh-issue-60402.iFz6X6.rst @@ -0,0 +1,2 @@ +In IDLE, Tab in a string that is not the start of a file name inserts a tab +instead of opening the completion list.