Skip to content

bpo-45495: Add 'case' and 'match' to IDLE completions list #29000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Lib/idlelib/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
import string
import sys

# Modified keyword list is used in fetch_completions.
completion_kwds = [s for s in keyword.kwlist
if s not in {'True', 'False', 'None'}] # In builtins.
completion_kwds.extend(('match', 'case')) # Context keywords.
completion_kwds.sort()

# Two types of completions; defined here for autocomplete_w import below.
ATTRS, FILES = 0, 1
from idlelib import autocomplete_w
Expand Down Expand Up @@ -177,9 +183,7 @@ def fetch_completions(self, what, mode):
namespace = {**__main__.__builtins__.__dict__,
**__main__.__dict__}
bigl = eval("dir()", namespace)
kwds = (s for s in keyword.kwlist
if s not in {'True', 'False', 'None'})
bigl.extend(kwds)
bigl.extend(completion_kwds)
bigl.sort()
if "__all__" in bigl:
smalll = sorted(eval("__all__", namespace))
Expand Down
5 changes: 5 additions & 0 deletions Lib/idlelib/idle_test/test_autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ def make_acw(): return self.dummy_acw()
self.assertTrue(acp.open_completions(ac.TAB))
self.text.delete('1.0', 'end')

def test_completion_kwds(self):
self.assertIn('and', ac.completion_kwds)
self.assertIn('case', ac.completion_kwds)
self.assertNotIn('None', ac.completion_kwds)

def test_fetch_completions(self):
# Test that fetch_completions returns 2 lists:
# For attribute completion, a large list containing all variables, and
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add context keywords 'case' and 'match' to completions list.