Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Lib/idlelib/colorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def make_pat():
]) +
r"))"
)
type_softkw = (
r"^[ \t]*" + # at beginning of line + possible indentation
r"(?P<TYPE_SOFTKW>type)" +
r"(?=[ \t]+[A-Za-z_])"
)
lazy_softkw = ( # lazy new in 3.15 (+ 2 lines below).
r"^[ \t]*" + # at beginning of line + possible indentation
r"(?P<LAZY_SOFTKW>lazy)" +
Expand All @@ -59,7 +64,7 @@ def make_pat():
dq3string = stringprefix + r'"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?'
string = any("STRING", [sq3string, dq3string, sqstring, dqstring])
prog = re.compile("|".join([
builtin, comment, string, kw,
type_softkw, builtin, comment, string, kw,
match_softkw, case_default,
case_softkw_and_pattern, lazy_softkw,
any("SYNC", [r"\n"]),
Expand All @@ -75,6 +80,7 @@ def make_pat():
"CASE_SOFTKW": "KEYWORD",
"CASE_DEFAULT_UNDERSCORE": "KEYWORD",
"CASE_SOFTKW2": "KEYWORD",
"TYPE_SOFTKW": "KEYWORD",
"LAZY_SOFTKW": "KEYWORD",
}

Expand Down
4 changes: 4 additions & 0 deletions Lib/idlelib/idle_test/test_colorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ async def f(): await g()
'''
case _:'''
"match x:"
type Point = tuple[float, float]
type = type(1)
""")


Expand Down Expand Up @@ -404,6 +406,8 @@ def test_recolorize_main(self, mock_notify):
('28.25', ('STRING',)), ('28.38', ('STRING',)),
('30.0', ('STRING',)),
('31.1', ('STRING',)),
('55.0', ('KEYWORD',)), ('55.4', ()), ('55.13', ('BUILTIN',)), ('55.19', ('BUILTIN',)),
('56.0', ('BUILTIN',)), ('56.7', ('BUILTIN',)),
# SYNC at the end of every line.
('1.55', ('SYNC',)), ('2.50', ('SYNC',)), ('3.34', ('SYNC',)),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IDLE now colorizes ``type`` as a soft keyword when it begins a statement.
Loading