Add support in IDLE colorizer

This commit is contained in:
Stan Ulbrych 2025-12-06 16:06:52 +00:00
parent e6633ffeb8
commit 2f642c89be
No known key found for this signature in database
GPG key ID: B8E58DBDB2A1A0B8
2 changed files with 23 additions and 1 deletions

View file

@ -42,6 +42,11 @@ def make_pat():
]) +
r"))"
)
lazy_softkw = (
r"^[ \t]*" + # at beginning of line + possible indentation
r"(?P<LAZY_SOFTKW>lazy)" +
r"(?=[ \t]+(?:import|from)\b)" # followed by 'import' or 'from'
)
builtinlist = [str(name) for name in dir(builtins)
if not name.startswith('_') and
name not in keyword.kwlist]
@ -56,7 +61,7 @@ def make_pat():
prog = re.compile("|".join([
builtin, comment, string, kw,
match_softkw, case_default,
case_softkw_and_pattern,
case_softkw_and_pattern, lazy_softkw,
any("SYNC", [r"\n"]),
]),
re.DOTALL | re.MULTILINE)
@ -70,6 +75,7 @@ def make_pat():
"CASE_SOFTKW": "KEYWORD",
"CASE_DEFAULT_UNDERSCORE": "KEYWORD",
"CASE_SOFTKW2": "KEYWORD",
"LAZY_SOFTKW": "KEYWORD",
}

View file

@ -542,6 +542,22 @@ def test_case_soft_keyword(self):
self._assert_highlighting('case _:', {'KEYWORD': [('1.0', '1.4'),
('1.5', '1.6')]})
def test_lazy_soft_keyword(self):
# lazy followed by import
self._assert_highlighting('lazy import foo',
{'KEYWORD': [('1.0', '1.4'), ('1.5', '1.11')]})
self._assert_highlighting(' lazy import foo',
{'KEYWORD': [('1.4', '1.8'), ('1.9', '1.15')]})
# lazy followed by from
self._assert_highlighting('lazy from foo import bar',
{'KEYWORD': [('1.0', '1.4'), ('1.5', '1.9'),
('1.14', '1.20')]})
# lazy not followed by import/from (not highlighted)
self._assert_highlighting('lazy = 1', {})
self._assert_highlighting('lazy foo', {})
def test_long_multiline_string(self):
source = textwrap.dedent('''\
"""a