[Python-checkins] gh-92032: Add soft keywords to rlcompleter (#92029)

JelleZijlstra webhook-mailer at python.org
Mon May 2 18:36:46 EDT 2022


https://github.com/python/cpython/commit/4bed9c47bd6c581c4c8ab59ab7acf0e57510d1f7
commit: 4bed9c47bd6c581c4c8ab59ab7acf0e57510d1f7
branch: main
author: kbeldan <kbeldan at users.noreply.github.com>
committer: JelleZijlstra <jelle.zijlstra at gmail.com>
date: 2022-05-02T16:36:29-06:00
summary:

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 at gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood at Gmail.com>

files:
A Misc/NEWS.d/next/Core and Builtins/2022-04-28-20-19-49.gh-issue-92032.ef-UfM.rst
M Lib/rlcompleter.py
M Lib/test/test_rlcompleter.py

diff --git a/Lib/rlcompleter.py b/Lib/rlcompleter.py
index 98b7930b32fab..4ede6dcce3fea 100644
--- a/Lib/rlcompleter.py
+++ b/Lib/rlcompleter.py
@@ -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__]:
diff --git a/Lib/test/test_rlcompleter.py b/Lib/test/test_rlcompleter.py
index 1f7a6ed3f639e..6b5fc9a0247f4 100644
--- a/Lib/test/test_rlcompleter.py
+++ b/Lib/test/test_rlcompleter.py
@@ -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 = {
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
index 0000000000000..f6f0db2c50cbc
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-04-28-20-19-49.gh-issue-92032.ef-UfM.rst	
@@ -0,0 +1,2 @@
+The interpreter can now autocomplete soft keywords, as of now
+``match``, ``case``, and ``_`` (wildcard pattern) from :pep:`634`.



More information about the Python-checkins mailing list