]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.15] gh-151390: Colorize `match +` and `match -` in the REPL (GH-151391) (#151476)
authorBartosz Sławecki <bartosz@ilikepython.com>
Sun, 14 Jun 2026 16:38:07 +0000 (18:38 +0200)
committerGitHub <noreply@github.com>
Sun, 14 Jun 2026 16:38:07 +0000 (16:38 +0000)
(cherry picked from commit a7007322c2a70b01e7c2a9e6b3f8f222d241c7d7)

Lib/_pyrepl/utils.py
Lib/test/test_pyrepl/test_utils.py
Misc/NEWS.d/next/Library/2026-06-12-07-20-08.gh-issue-151390.CmYN9EeJ.rst [new file with mode: 0644]

index b50426c31ead53a8015124943b061ed168289494..4d1f936b4224ad505968cfa55bc3daaf47fb1000 100644 (file)
@@ -259,7 +259,7 @@ def is_soft_keyword_used(*tokens: TI | None) -> bool:
             None | TI(T.NEWLINE) | TI(T.INDENT) | TI(string=":"),
             TI(string="match"),
             TI(T.NUMBER | T.STRING | T.FSTRING_START | T.TSTRING_START)
-            | TI(T.OP, string="(" | "*" | "[" | "{" | "~" | "...")
+            | TI(T.OP, string="(" | "*" | "-" | "+" | "[" | "{" | "~" | "...")
         ):
             return True
         case (
index 3c55b6bdaeee9e85abcd4f204876bd5968880d05..e8157f164b3063af5edbf93ccbb4b08e900cec8c 100644 (file)
@@ -125,6 +125,22 @@ class TestUtils(TestCase):
                     ("import", "keyword"),
                 ],
             ),
+            (
+                "match +1",
+                [
+                    ("match", "soft_keyword"),
+                    ("+", "op"),
+                    ("1", "number"),
+                ],
+            ),
+            (
+                "match -1",
+                [
+                    ("match", "soft_keyword"),
+                    ("-", "op"),
+                    ("1", "number"),
+                ],
+            ),
         ]
         for code, expected_highlights in cases:
             with self.subTest(code=code):
diff --git a/Misc/NEWS.d/next/Library/2026-06-12-07-20-08.gh-issue-151390.CmYN9EeJ.rst b/Misc/NEWS.d/next/Library/2026-06-12-07-20-08.gh-issue-151390.CmYN9EeJ.rst
new file mode 100644 (file)
index 0000000..ff8de30
--- /dev/null
@@ -0,0 +1 @@
+Colorize ``match`` in the :term:`REPL` when followed by a unary ``+`` or ``-`` operator. Patch by Bartosz Sławecki.