Skip to content

Commit 08c90ef

Browse files
serhiy-storchakaserwyclaude
committed
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 <roger.serwy@gmail.com> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 82952e3 commit 08c90ef

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

Lib/idlelib/autocomplete.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ def open_completions(self, args):
153153
comp_lists = self.fetch_completions(comp_what, mode)
154154
if not comp_lists[0]:
155155
return None
156+
if (complete and mode == FILES
157+
and not any(name.startswith(comp_start)
158+
for name in comp_lists[0])):
159+
# Nothing to complete; insert a tab.
160+
return None
156161
self.autocompletewindow = self._make_autocomplete_window()
157162
return not self.autocompletewindow.show_window(
158163
comp_lists, "insert-%dc" % len(comp_start),

Lib/idlelib/idle_test/test_autocomplete.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ def make_acw(): return self.dummy_acw()
218218
self.assertTrue(acp.open_completions(ac.TAB))
219219
self.text.delete('1.0', 'end')
220220

221+
# No file name starts with the text (gh-60402).
222+
self.text.insert('1.0', '"hello wor')
223+
self.assertIsNone(acp.open_completions(ac.TAB))
224+
self.assertTrue(acp.open_completions(ac.FORCE))
225+
self.text.delete('1.0', 'end')
226+
221227
def test_completion_kwds(self):
222228
self.assertIn('and', ac.completion_kwds)
223229
self.assertIn('case', ac.completion_kwds)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
In IDLE, Tab in a string that is not the start of a file name inserts a tab
2+
instead of opening the completion list.

0 commit comments

Comments
 (0)