From: kbeldan Date: Mon, 2 May 2022 22:36:29 +0000 (+0000) Subject: gh-92032: Add soft keywords to rlcompleter (#92029) X-Git-Tag: v3.11.0b1~112 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4bed9c47bd6c581c4c8ab59ab7acf0e57510d1f7;p=thirdparty%2FPython%2Fcpython.git 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 Co-authored-by: Alex Waygood --- diff --git a/Lib/rlcompleter.py b/Lib/rlcompleter.py index 98b7930b32fa..4ede6dcce3fe 100644 --- a/Lib/rlcompleter.py +++ b/Lib/rlcompleter.py @@ -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__]: diff --git a/Lib/test/test_rlcompleter.py b/Lib/test/test_rlcompleter.py index 1f7a6ed3f639..6b5fc9a0247f 100644 --- a/Lib/test/test_rlcompleter.py +++ b/Lib/test/test_rlcompleter.py @@ -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 index 000000000000..f6f0db2c50cb --- /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`.