From c663b10ecb401ea90533d1228bdadd02e6cde1b1 Mon Sep 17 00:00:00 2001 From: Karl Beldan Date: Thu, 28 Apr 2022 18:50:16 +0000 Subject: [PATCH 1/4] gh-92032: Add soft keywords to rlcompleter Let the interpreter autocomplete soft-keywords, ATM the PEP-634 'match' / 'case' / '_' (wildcard pattern). --- Lib/rlcompleter.py | 4 ++-- Lib/test/test_rlcompleter.py | 3 +++ .../2022-04-28-20-19-49.gh-issue-92032.ef-UfM.rst | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-04-28-20-19-49.gh-issue-92032.ef-UfM.rst diff --git a/Lib/rlcompleter.py b/Lib/rlcompleter.py index 98b7930b32fab3..4ede6dcce3fea2 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 1f7a6ed3f639e0..6b5fc9a0247f4b 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 00000000000000..bdde5e204617f1 --- /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 @@ +The interpreter can now autocomplete soft keywords, as of now the PEP-634 match / case / _(wildcard pattern). From 94686fb9ce485f24e1c048e845fd3e30b1d28c60 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 2 May 2022 10:51:43 -0600 Subject: [PATCH 2/4] Update Misc/NEWS.d/next/Core and Builtins/2022-04-28-20-19-49.gh-issue-92032.ef-UfM.rst --- .../2022-04-28-20-19-49.gh-issue-92032.ef-UfM.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 index bdde5e204617f1..b3f64541a11583 100644 --- 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 @@ -1 +1,2 @@ -The interpreter can now autocomplete soft keywords, as of now the PEP-634 match / case / _(wildcard pattern). +The interpreter can now autocomplete soft keywords, as of now +`match`, `case`, and `_` (wildcard pattern) from :pep:`634`. From 47a2c6b16f49da494b9f664fdb636a96f328ee33 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 2 May 2022 11:37:18 -0600 Subject: [PATCH 3/4] Update Misc/NEWS.d/next/Core and Builtins/2022-04-28-20-19-49.gh-issue-92032.ef-UfM.rst Co-authored-by: Alex Waygood --- .../2022-04-28-20-19-49.gh-issue-92032.ef-UfM.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index b3f64541a11583..948fe4de90e708 100644 --- 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 @@ -1,2 +1,2 @@ -The interpreter can now autocomplete soft keywords, as of now +The interpreter can now autocomplete soft keywords, as of now `match`, `case`, and `_` (wildcard pattern) from :pep:`634`. From ba9f9a3b2488c141fcdf1beabdfb3b00c6a328e0 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 2 May 2022 11:37:50 -0600 Subject: [PATCH 4/4] Update Misc/NEWS.d/next/Core and Builtins/2022-04-28-20-19-49.gh-issue-92032.ef-UfM.rst --- .../2022-04-28-20-19-49.gh-issue-92032.ef-UfM.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 948fe4de90e708..f6f0db2c50cbc6 100644 --- 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 @@ -1,2 +1,2 @@ The interpreter can now autocomplete soft keywords, as of now -`match`, `case`, and `_` (wildcard pattern) from :pep:`634`. +``match``, ``case``, and ``_`` (wildcard pattern) from :pep:`634`.