https://github.com/python/cpython/commit/68ed7a50226f8981788f2673677e30f1431e18a9
commit: 68ed7a50226f8981788f2673677e30f1431e18a9
branch: main
author: Locked-chess-official <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-09-23T13:54:26+03:00
summary:

gh-151471: Colorize the soft keyword `type` in IDLE (GH-151700)

`type` is now colored as a keyword when it starts a statement and is
followed by a name, as in `type Point = tuple[float, float]`.  It stays
a builtin elsewhere, for example in `type = type(1)`, `type(x)` or
`type in (int, str)`.

files:
A Misc/NEWS.d/next/IDLE/2026-09-17-08-53-12.gh-issue-151471.-yvE03.rst
M Lib/idlelib/colorizer.py
M Lib/idlelib/idle_test/test_colorizer.py

diff --git a/Lib/idlelib/colorizer.py b/Lib/idlelib/colorizer.py
index ac12d8ace3575f..5f18a22d2f0507 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"(?P<TYPE_SOFTKW>type)" +
+        r"(?=[ \t]+(?!(?:" + "|".join(keyword.kwlist) + r")\b)[^\W\d])"
+    )
     lazy_softkw = (  # lazy new in 3.15 (+ 2 lines below).
         r"^[ \t]*" +  # at beginning of line + possible indentation
         r"(?P<LAZY_SOFTKW>lazy)" +
@@ -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/Lib/idlelib/idle_test/test_colorizer.py 
b/Lib/idlelib/idle_test/test_colorizer.py
index 8a6ab527f9387f..5bb4f5b3ff36e6 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',)),
+                    ('32.0', ('KEYWORD',)),
+                    ('33.0', ('BUILTIN',)), ('33.1', ('BUILTIN',)),
                     # SYNC at the end of every line.
                     ('1.55', ('SYNC',)), ('2.50', ('SYNC',)), ('3.34', 
('SYNC',)),
                    )
@@ -434,7 +438,7 @@ def test_recolorize_main(self, mock_notify):
         eq(text.tag_nextrange('STRING', '8.12'), ('8.14', '8.17'))
         eq(text.tag_nextrange('STRING', '8.17'), ('8.19', '8.26'))
         eq(text.tag_nextrange('SYNC', '8.0'), ('8.26', '9.0'))
-        eq(text.tag_nextrange('SYNC', '31.0'), ('31.10', '33.0'))
+        eq(text.tag_nextrange('SYNC', '31.0'), ('31.10', '32.0'))
 
     def _assert_highlighting(self, source, tag_ranges):
         """Check highlighting of a given piece of code.
diff --git 
a/Misc/NEWS.d/next/IDLE/2026-09-17-08-53-12.gh-issue-151471.-yvE03.rst 
b/Misc/NEWS.d/next/IDLE/2026-09-17-08-53-12.gh-issue-151471.-yvE03.rst
new file mode 100644
index 00000000000000..cc04822f6d3321
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2026-09-17-08-53-12.gh-issue-151471.-yvE03.rst
@@ -0,0 +1 @@
+Colorize the soft keyword ``type`` in IDLE.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to