mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
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 <jelle.zijlstra@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
cc6ae4f483
commit
4bed9c47bd
3 changed files with 7 additions and 2 deletions
|
@ -117,14 +117,14 @@ class Completer:
|
||||||
matches = []
|
matches = []
|
||||||
seen = {"__builtins__"}
|
seen = {"__builtins__"}
|
||||||
n = len(text)
|
n = len(text)
|
||||||
for word in keyword.kwlist:
|
for word in keyword.kwlist + keyword.softkwlist:
|
||||||
if word[:n] == text:
|
if word[:n] == text:
|
||||||
seen.add(word)
|
seen.add(word)
|
||||||
if word in {'finally', 'try'}:
|
if word in {'finally', 'try'}:
|
||||||
word = word + ':'
|
word = word + ':'
|
||||||
elif word not in {'False', 'None', 'True',
|
elif word not in {'False', 'None', 'True',
|
||||||
'break', 'continue', 'pass',
|
'break', 'continue', 'pass',
|
||||||
'else'}:
|
'else', '_'}:
|
||||||
word = word + ' '
|
word = word + ' '
|
||||||
matches.append(word)
|
matches.append(word)
|
||||||
for nspace in [self.namespace, builtins.__dict__]:
|
for nspace in [self.namespace, builtins.__dict__]:
|
||||||
|
|
|
@ -138,6 +138,9 @@ class TestRlcompleter(unittest.TestCase):
|
||||||
self.assertEqual(completer.complete('el', 0), 'elif ')
|
self.assertEqual(completer.complete('el', 0), 'elif ')
|
||||||
self.assertEqual(completer.complete('el', 1), 'else')
|
self.assertEqual(completer.complete('el', 1), 'else')
|
||||||
self.assertEqual(completer.complete('tr', 0), 'try:')
|
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):
|
def test_duplicate_globals(self):
|
||||||
namespace = {
|
namespace = {
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
The interpreter can now autocomplete soft keywords, as of now
|
||||||
|
``match``, ``case``, and ``_`` (wildcard pattern) from :pep:`634`.
|
Loading…
Add table
Add a link
Reference in a new issue