]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-138239: Fix incorrect highlighting of "type" in type statements in the REPL (GH...
author00ll00 <40747228+00ll00@users.noreply.github.com>
Mon, 15 Sep 2025 16:21:41 +0000 (00:21 +0800)
committerGitHub <noreply@github.com>
Mon, 15 Sep 2025 16:21:41 +0000 (18:21 +0200)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Lib/_pyrepl/utils.py
Lib/test/test_pyrepl/test_reader.py
Misc/NEWS.d/next/Library/2025-08-29-12-56-55.gh-issue-138239.uthZFI.rst [new file with mode: 0644]

index d32fce591fadcc2d3be568f0f5836120442ec031..2ffd547f99d7c5e93d29bb8e221a69400b37b61e 100644 (file)
@@ -263,6 +263,12 @@ def is_soft_keyword_used(*tokens: TI | None) -> bool:
             return True
         case (TI(string="case"), TI(string="_"), TI(string=":")):
             return True
+        case (
+            None | TI(T.NEWLINE) | TI(T.INDENT) | TI(T.DEDENT) | TI(string=":"),
+            TI(string="type"),
+            TI(T.NAME, string=s)
+        ):
+            return not keyword.iskeyword(s)
         case _:
             return False
 
index 9a02dff7387563630831c64bbb3b2f5cd1e30a42..b1b6ae16a1e592cac2487e4e89539551a940e101 100644 (file)
@@ -378,6 +378,7 @@ class TestReaderInColor(ScreenEqualMixin, TestCase):
                     case "ios" | "android":
                         print("on the phone")
                     case _: print('arms around', match.group(1))
+            type type = type[type]
             """
         )
         expected = dedent(
@@ -397,6 +398,7 @@ class TestReaderInColor(ScreenEqualMixin, TestCase):
                     {K}case{z} {s}"ios"{z} {o}|{z} {s}"android"{z}{o}:{z}
                         {b}print{z}{o}({z}{s}"on the phone"{z}{o}){z}
                     {K}case{z} {K}_{z}{o}:{z} {b}print{z}{o}({z}{s}'arms around'{z}{o},{z} match{o}.{z}group{o}({z}{n}1{z}{o}){z}{o}){z}
+            {K}type{z} {b}type{z} {o}={z} {b}type{z}{o}[{z}{b}type{z}{o}]{z}
             """
         )
         expected_sync = expected.format(a="", **colors)
@@ -404,14 +406,14 @@ class TestReaderInColor(ScreenEqualMixin, TestCase):
         reader, _ = handle_all_events(events)
         self.assert_screen_equal(reader, code, clean=True)
         self.assert_screen_equal(reader, expected_sync)
-        self.assertEqual(reader.pos, 396)
-        self.assertEqual(reader.cxy, (0, 15))
+        self.assertEqual(reader.pos, 419)
+        self.assertEqual(reader.cxy, (0, 16))
 
         async_msg = "{k}async{z} ".format(**colors)
         expected_async = expected.format(a=async_msg, **colors)
         more_events = itertools.chain(
             code_to_events(code),
-            [Event(evt="key", data="up", raw=bytearray(b"\x1bOA"))] * 14,
+            [Event(evt="key", data="up", raw=bytearray(b"\x1bOA"))] * 15,
             code_to_events("async "),
         )
         reader, _ = handle_all_events(more_events)
diff --git a/Misc/NEWS.d/next/Library/2025-08-29-12-56-55.gh-issue-138239.uthZFI.rst b/Misc/NEWS.d/next/Library/2025-08-29-12-56-55.gh-issue-138239.uthZFI.rst
new file mode 100644 (file)
index 0000000..9e0218e
--- /dev/null
@@ -0,0 +1,2 @@
+The REPL now highlights :keyword:`type` as a soft keyword
+in :ref:`type statements <type>`.