From 51f2dc58d52df98f1b7af2ca16c9d13df3b5a876 Mon Sep 17 00:00:00 2001 From: Abdullah Masood Date: Mon, 17 Aug 2026 17:52:14 +0500 Subject: [PATCH 1/2] gh-151471: IDLE colorizes type as a soft keyword --- Lib/idlelib/colorizer.py | 8 +++++++- .../IDLE/2026-08-17-17-51-00.gh-issue-151471.abcdef.rst | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/IDLE/2026-08-17-17-51-00.gh-issue-151471.abcdef.rst diff --git a/Lib/idlelib/colorizer.py b/Lib/idlelib/colorizer.py index ac12d8ace3575f3..d5f883ee04f2537 100644 --- a/Lib/idlelib/colorizer.py +++ b/Lib/idlelib/colorizer.py @@ -42,6 +42,11 @@ def make_pat(): ]) + r"))" ) + type_softkw = ( + r"^[ \t]*" + # at beginning of line + possible indentation + r"(?Ptype)" + + r"(?=[ \t]+[A-Za-z_])" + ) lazy_softkw = ( # lazy new in 3.15 (+ 2 lines below). r"^[ \t]*" + # at beginning of line + possible indentation r"(?Plazy)" + @@ -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"]), @@ -75,6 +80,7 @@ def make_pat(): "CASE_SOFTKW": "KEYWORD", "CASE_DEFAULT_UNDERSCORE": "KEYWORD", "CASE_SOFTKW2": "KEYWORD", + "TYPE_SOFTKW": "KEYWORD", "LAZY_SOFTKW": "KEYWORD", } diff --git a/Misc/NEWS.d/next/IDLE/2026-08-17-17-51-00.gh-issue-151471.abcdef.rst b/Misc/NEWS.d/next/IDLE/2026-08-17-17-51-00.gh-issue-151471.abcdef.rst new file mode 100644 index 000000000000000..32099ed34aa6fb4 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2026-08-17-17-51-00.gh-issue-151471.abcdef.rst @@ -0,0 +1 @@ +IDLE now colorizes ``type`` as a soft keyword when it begins a statement. From b752e2c790498ed6ff73689a43610cedb7156843 Mon Sep 17 00:00:00 2001 From: Abdullah Masood Date: Mon, 17 Aug 2026 22:44:45 +0500 Subject: [PATCH 2/2] Add tests for type soft keyword colorizer --- Lib/idlelib/idle_test/test_colorizer.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/idlelib/idle_test/test_colorizer.py b/Lib/idlelib/idle_test/test_colorizer.py index 8a6ab527f9387f4..a70f809729229a4 100644 --- a/Lib/idlelib/idle_test/test_colorizer.py +++ b/Lib/idlelib/idle_test/test_colorizer.py @@ -52,6 +52,8 @@ async def f(): await g() ''' case _:''' "match x:" + type Point = tuple[float, float] + type = type(1) """) @@ -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',)), )