[Python-checkins] [3.10] bpo-45495: Add 'case' and 'match' to IDLE completions list. (GH-29000) (GH-29001)

miss-islington webhook-mailer at python.org
Sat Oct 16 19:14:20 EDT 2021


https://github.com/python/cpython/commit/a29470307308f64af9c55263cdd6e1984ba89925
commit: a29470307308f64af9c55263cdd6e1984ba89925
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-10-16T16:14:11-07:00
summary:

[3.10] bpo-45495: Add 'case' and 'match' to IDLE completions list. (GH-29000) (GH-29001)



Since the keyword list is frozen, only compute it once per
session.  The colorizer already handles context keywords.
(cherry picked from commit 42ac06dcd234bdda989dcfe854ac5173337024c9)


Co-authored-by: Terry Jan Reedy <tjreedy at udel.edu>

Automerge-Triggered-By: GH:terryjreedy

files:
A Misc/NEWS.d/next/IDLE/2021-10-16-17-20-32.bpo-45495.ST8RFt.rst
M Lib/idlelib/autocomplete.py
M Lib/idlelib/idle_test/test_autocomplete.py

diff --git a/Lib/idlelib/autocomplete.py b/Lib/idlelib/autocomplete.py
index bb7ee035c4fef..032d31225315f 100644
--- a/Lib/idlelib/autocomplete.py
+++ b/Lib/idlelib/autocomplete.py
@@ -9,6 +9,12 @@
 import string
 import sys
 
+# Modified keyword list is used in fetch_completions.
+completion_kwds = [s for s in keyword.kwlist
+                     if s not in {'True', 'False', 'None'}]  # In builtins.
+completion_kwds.extend(('match', 'case'))  # Context keywords.
+completion_kwds.sort()
+
 # Two types of completions; defined here for autocomplete_w import below.
 ATTRS, FILES = 0, 1
 from idlelib import autocomplete_w
@@ -177,9 +183,7 @@ def fetch_completions(self, what, mode):
                     namespace = {**__main__.__builtins__.__dict__,
                                  **__main__.__dict__}
                     bigl = eval("dir()", namespace)
-                    kwds = (s for s in keyword.kwlist
-                            if s not in {'True', 'False', 'None'})
-                    bigl.extend(kwds)
+                    bigl.extend(completion_kwds)
                     bigl.sort()
                     if "__all__" in bigl:
                         smalll = sorted(eval("__all__", namespace))
diff --git a/Lib/idlelib/idle_test/test_autocomplete.py b/Lib/idlelib/idle_test/test_autocomplete.py
index 642bb5db64dc3..a811363c18d04 100644
--- a/Lib/idlelib/idle_test/test_autocomplete.py
+++ b/Lib/idlelib/idle_test/test_autocomplete.py
@@ -218,6 +218,11 @@ def make_acw(): return self.dummy_acw()
         self.assertTrue(acp.open_completions(ac.TAB))
         self.text.delete('1.0', 'end')
 
+    def test_completion_kwds(self):
+        self.assertIn('and', ac.completion_kwds)
+        self.assertIn('case', ac.completion_kwds)
+        self.assertNotIn('None', ac.completion_kwds)
+
     def test_fetch_completions(self):
         # Test that fetch_completions returns 2 lists:
         # For attribute completion, a large list containing all variables, and
diff --git a/Misc/NEWS.d/next/IDLE/2021-10-16-17-20-32.bpo-45495.ST8RFt.rst b/Misc/NEWS.d/next/IDLE/2021-10-16-17-20-32.bpo-45495.ST8RFt.rst
new file mode 100644
index 0000000000000..3868f8d136a04
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2021-10-16-17-20-32.bpo-45495.ST8RFt.rst
@@ -0,0 +1 @@
+Add context keywords 'case' and 'match' to completions list.



More information about the Python-checkins mailing list