Skip to content

Commit

Permalink
gh-92032: Add soft keywords to rlcompleter (#92029)
Browse files Browse the repository at this point in the history
Let the interpreter autocomplete soft-keywords, ATM the PEP-634 'match'
/ 'case' / '_' (wildcard pattern).

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
  • Loading branch information
3 people committed May 2, 2022
1 parent cc6ae4f commit 4bed9c4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Lib/rlcompleter.py
Expand Up @@ -117,14 +117,14 @@ def global_matches(self, text):
matches = []
seen = {"__builtins__"}
n = len(text)
for word in keyword.kwlist:
for word in keyword.kwlist + keyword.softkwlist:
if word[:n] == text:
seen.add(word)
if word in {'finally', 'try'}:
word = word + ':'
elif word not in {'False', 'None', 'True',
'break', 'continue', 'pass',
'else'}:
'else', '_'}:
word = word + ' '
matches.append(word)
for nspace in [self.namespace, builtins.__dict__]:
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_rlcompleter.py
Expand Up @@ -138,6 +138,9 @@ def test_complete(self):
self.assertEqual(completer.complete('el', 0), 'elif ')
self.assertEqual(completer.complete('el', 1), 'else')
self.assertEqual(completer.complete('tr', 0), 'try:')
self.assertEqual(completer.complete('_', 0), '_')
self.assertEqual(completer.complete('match', 0), 'match ')
self.assertEqual(completer.complete('case', 0), 'case ')

def test_duplicate_globals(self):
namespace = {
Expand Down
@@ -0,0 +1,2 @@
The interpreter can now autocomplete soft keywords, as of now
``match``, ``case``, and ``_`` (wildcard pattern) from :pep:`634`.

0 comments on commit 4bed9c4

Please sign in to comment.