Skip to content

Commit fbe3137

Browse files
committed
[3.14] gh-151390: Colorize match + and match - in the REPL (GH-151391)
(cherry picked from commit a700732) Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
1 parent 3ad080a commit fbe3137

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

Lib/_pyrepl/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def is_soft_keyword_used(*tokens: TI | None) -> bool:
242242
None | TI(T.NEWLINE) | TI(T.INDENT) | TI(string=":"),
243243
TI(string="match"),
244244
TI(T.NUMBER | T.STRING | T.FSTRING_START | T.TSTRING_START)
245-
| TI(T.OP, string="(" | "*" | "[" | "{" | "~" | "...")
245+
| TI(T.OP, string="(" | "*" | "-" | "+" | "[" | "{" | "~" | "...")
246246
):
247247
return True
248248
case (

Lib/test/test_pyrepl/test_utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ def test_gen_colors_keyword_highlighting(self):
9393
("set", [("set", "builtin")]),
9494
("list", [("list", "builtin")]),
9595
(" \n dict", [("dict", "builtin")]),
96+
(
97+
"match +1",
98+
[
99+
("match", "soft_keyword"),
100+
("+", "op"),
101+
("1", "number"),
102+
],
103+
),
104+
(
105+
"match -1",
106+
[
107+
("match", "soft_keyword"),
108+
("-", "op"),
109+
("1", "number"),
110+
],
111+
),
96112
]
97113
for code, expected_highlights in cases:
98114
with self.subTest(code=code):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Colorize ``match`` in the :term:`REPL` when followed by a unary ``+`` or ``-`` operator. Patch by Bartosz Sławecki.

0 commit comments

Comments
 (0)