mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00
[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 42ac06dcd2
)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Automerge-Triggered-By: GH:terryjreedy
This commit is contained in:
parent
5df35faf36
commit
a294703073
3 changed files with 13 additions and 3 deletions
|
@ -9,6 +9,12 @@ import os
|
||||||
import string
|
import string
|
||||||
import sys
|
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.
|
# Two types of completions; defined here for autocomplete_w import below.
|
||||||
ATTRS, FILES = 0, 1
|
ATTRS, FILES = 0, 1
|
||||||
from idlelib import autocomplete_w
|
from idlelib import autocomplete_w
|
||||||
|
@ -177,9 +183,7 @@ class AutoComplete:
|
||||||
namespace = {**__main__.__builtins__.__dict__,
|
namespace = {**__main__.__builtins__.__dict__,
|
||||||
**__main__.__dict__}
|
**__main__.__dict__}
|
||||||
bigl = eval("dir()", namespace)
|
bigl = eval("dir()", namespace)
|
||||||
kwds = (s for s in keyword.kwlist
|
bigl.extend(completion_kwds)
|
||||||
if s not in {'True', 'False', 'None'})
|
|
||||||
bigl.extend(kwds)
|
|
||||||
bigl.sort()
|
bigl.sort()
|
||||||
if "__all__" in bigl:
|
if "__all__" in bigl:
|
||||||
smalll = sorted(eval("__all__", namespace))
|
smalll = sorted(eval("__all__", namespace))
|
||||||
|
|
|
@ -218,6 +218,11 @@ class AutoCompleteTest(unittest.TestCase):
|
||||||
self.assertTrue(acp.open_completions(ac.TAB))
|
self.assertTrue(acp.open_completions(ac.TAB))
|
||||||
self.text.delete('1.0', 'end')
|
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):
|
def test_fetch_completions(self):
|
||||||
# Test that fetch_completions returns 2 lists:
|
# Test that fetch_completions returns 2 lists:
|
||||||
# For attribute completion, a large list containing all variables, and
|
# For attribute completion, a large list containing all variables, and
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Add context keywords 'case' and 'match' to completions list.
|
Loading…
Add table
Add a link
Reference in a new issue