Skip to content

Commit a294703

Browse files
[3.10] bpo-45495: Add 'case' and 'match' to IDLE completions list. (GH-29000) (GH-29001)
Since the keyword list is frozen, only compute it once per session. The colorizer already handles context keywords. (cherry picked from commit 42ac06d) Co-authored-by: Terry Jan Reedy <[email protected]> Automerge-Triggered-By: GH:terryjreedy
1 parent 5df35fa commit a294703

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

Lib/idlelib/autocomplete.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
import string
1010
import sys
1111

12+
# Modified keyword list is used in fetch_completions.
13+
completion_kwds = [s for s in keyword.kwlist
14+
if s not in {'True', 'False', 'None'}] # In builtins.
15+
completion_kwds.extend(('match', 'case')) # Context keywords.
16+
completion_kwds.sort()
17+
1218
# Two types of completions; defined here for autocomplete_w import below.
1319
ATTRS, FILES = 0, 1
1420
from idlelib import autocomplete_w
@@ -177,9 +183,7 @@ def fetch_completions(self, what, mode):
177183
namespace = {**__main__.__builtins__.__dict__,
178184
**__main__.__dict__}
179185
bigl = eval("dir()", namespace)
180-
kwds = (s for s in keyword.kwlist
181-
if s not in {'True', 'False', 'None'})
182-
bigl.extend(kwds)
186+
bigl.extend(completion_kwds)
183187
bigl.sort()
184188
if "__all__" in bigl:
185189
smalll = sorted(eval("__all__", namespace))

Lib/idlelib/idle_test/test_autocomplete.py

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

221+
def test_completion_kwds(self):
222+
self.assertIn('and', ac.completion_kwds)
223+
self.assertIn('case', ac.completion_kwds)
224+
self.assertNotIn('None', ac.completion_kwds)
225+
221226
def test_fetch_completions(self):
222227
# Test that fetch_completions returns 2 lists:
223228
# For attribute completion, a large list containing all variables, and
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add context keywords 'case' and 'match' to completions list.

0 commit comments

Comments
 (0)