Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4bed9c4

Browse files
kbeldanJelleZijlstraAlexWaygood
authored
gh-92032: Add soft keywords to rlcompleter (#92029)
Let the interpreter autocomplete soft-keywords, ATM the PEP-634 'match' / 'case' / '_' (wildcard pattern). Co-authored-by: Jelle Zijlstra <[email protected]> Co-authored-by: Alex Waygood <[email protected]>
1 parent cc6ae4f commit 4bed9c4

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

Lib/rlcompleter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ def global_matches(self, text):
117117
matches = []
118118
seen = {"__builtins__"}
119119
n = len(text)
120-
for word in keyword.kwlist:
120+
for word in keyword.kwlist + keyword.softkwlist:
121121
if word[:n] == text:
122122
seen.add(word)
123123
if word in {'finally', 'try'}:
124124
word = word + ':'
125125
elif word not in {'False', 'None', 'True',
126126
'break', 'continue', 'pass',
127-
'else'}:
127+
'else', '_'}:
128128
word = word + ' '
129129
matches.append(word)
130130
for nspace in [self.namespace, builtins.__dict__]:

Lib/test/test_rlcompleter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ def test_complete(self):
138138
self.assertEqual(completer.complete('el', 0), 'elif ')
139139
self.assertEqual(completer.complete('el', 1), 'else')
140140
self.assertEqual(completer.complete('tr', 0), 'try:')
141+
self.assertEqual(completer.complete('_', 0), '_')
142+
self.assertEqual(completer.complete('match', 0), 'match ')
143+
self.assertEqual(completer.complete('case', 0), 'case ')
141144

142145
def test_duplicate_globals(self):
143146
namespace = {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The interpreter can now autocomplete soft keywords, as of now
2+
``match``, ``case``, and ``_`` (wildcard pattern) from :pep:`634`.

0 commit comments

Comments
 (0)