]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-151390: Colorize `match +` and `match -` in the REPL (#151391)
authorBartosz Sławecki <bartosz@ilikepython.com>
Sun, 14 Jun 2026 16:06:30 +0000 (18:06 +0200)
committerGitHub <noreply@github.com>
Sun, 14 Jun 2026 16:06:30 +0000 (19:06 +0300)
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 f2837a1b8eb95e7685d05bcf4c9e28e6bd6d1fe0..230dae35af665ab0226393a4c1db729e6eab46a7 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 0b873d32b62b5d26938dc7b162667c9dfac628c4..ebbd06213c69affac2a4860388ddf7abff653b01 100644 (file)
@@ -133,6 +133,22 @@ class TestUtils(TestCase):
                     ("1", "number"),
                 ],
             ),
+            (
+                "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.