Skip to content

Commit ab07b14

Browse files
authored
Merge pull request #22 from StanFromIreland/lazy-idle
2 parents e6633ff + 2f642c8 commit ab07b14

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Lib/idlelib/colorizer.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ def make_pat():
4242
]) +
4343
r"))"
4444
)
45+
lazy_softkw = (
46+
r"^[ \t]*" + # at beginning of line + possible indentation
47+
r"(?P<LAZY_SOFTKW>lazy)" +
48+
r"(?=[ \t]+(?:import|from)\b)" # followed by 'import' or 'from'
49+
)
4550
builtinlist = [str(name) for name in dir(builtins)
4651
if not name.startswith('_') and
4752
name not in keyword.kwlist]
@@ -56,7 +61,7 @@ def make_pat():
5661
prog = re.compile("|".join([
5762
builtin, comment, string, kw,
5863
match_softkw, case_default,
59-
case_softkw_and_pattern,
64+
case_softkw_and_pattern, lazy_softkw,
6065
any("SYNC", [r"\n"]),
6166
]),
6267
re.DOTALL | re.MULTILINE)
@@ -70,6 +75,7 @@ def make_pat():
7075
"CASE_SOFTKW": "KEYWORD",
7176
"CASE_DEFAULT_UNDERSCORE": "KEYWORD",
7277
"CASE_SOFTKW2": "KEYWORD",
78+
"LAZY_SOFTKW": "KEYWORD",
7379
}
7480

7581

Lib/idlelib/idle_test/test_colorizer.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,22 @@ def test_case_soft_keyword(self):
542542
self._assert_highlighting('case _:', {'KEYWORD': [('1.0', '1.4'),
543543
('1.5', '1.6')]})
544544

545+
def test_lazy_soft_keyword(self):
546+
# lazy followed by import
547+
self._assert_highlighting('lazy import foo',
548+
{'KEYWORD': [('1.0', '1.4'), ('1.5', '1.11')]})
549+
self._assert_highlighting(' lazy import foo',
550+
{'KEYWORD': [('1.4', '1.8'), ('1.9', '1.15')]})
551+
552+
# lazy followed by from
553+
self._assert_highlighting('lazy from foo import bar',
554+
{'KEYWORD': [('1.0', '1.4'), ('1.5', '1.9'),
555+
('1.14', '1.20')]})
556+
557+
# lazy not followed by import/from (not highlighted)
558+
self._assert_highlighting('lazy = 1', {})
559+
self._assert_highlighting('lazy foo', {})
560+
545561
def test_long_multiline_string(self):
546562
source = textwrap.dedent('''\
547563
"""a

0 commit comments

Comments
 (0)