]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-92032: Add soft keywords to rlcompleter (#92029)
authorkbeldan <kbeldan@users.noreply.github.com>
Mon, 2 May 2022 22:36:29 +0000 (22:36 +0000)
committerGitHub <noreply@github.com>
Mon, 2 May 2022 22:36:29 +0000 (16:36 -0600)
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>
Lib/rlcompleter.py
Lib/test/test_rlcompleter.py
Misc/NEWS.d/next/Core and Builtins/2022-04-28-20-19-49.gh-issue-92032.ef-UfM.rst [new file with mode: 0644]

index 98b7930b32fab32e387500dee01c7a2a68eb2e3a..4ede6dcce3fea293fb3241029d00393ff1077ab1 100644 (file)
@@ -117,14 +117,14 @@ class Completer:
         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__]:
index 1f7a6ed3f639e06374fb2de956f8e222bd83d4b0..6b5fc9a0247f4b59097658cfc73b811cbf336722 100644 (file)
@@ -138,6 +138,9 @@ class TestRlcompleter(unittest.TestCase):
         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 = {
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-04-28-20-19-49.gh-issue-92032.ef-UfM.rst b/Misc/NEWS.d/next/Core and Builtins/2022-04-28-20-19-49.gh-issue-92032.ef-UfM.rst
new file mode 100644 (file)
index 0000000..f6f0db2
--- /dev/null
@@ -0,0 +1,2 @@
+The interpreter can now autocomplete soft keywords, as of now
+``match``, ``case``, and ``_`` (wildcard pattern) from :pep:`634`.