Skip to content

Commit 114a7a8

Browse files
authored
[3.15] gh-151390: Colorize match + and match - in the REPL (GH-151391) (#151476)
(cherry picked from commit a700732)
1 parent 89e178d commit 114a7a8

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
@@ -259,7 +259,7 @@ def is_soft_keyword_used(*tokens: TI | None) -> bool:
259259
None | TI(T.NEWLINE) | TI(T.INDENT) | TI(string=":"),
260260
TI(string="match"),
261261
TI(T.NUMBER | T.STRING | T.FSTRING_START | T.TSTRING_START)
262-
| TI(T.OP, string="(" | "*" | "[" | "{" | "~" | "...")
262+
| TI(T.OP, string="(" | "*" | "-" | "+" | "[" | "{" | "~" | "...")
263263
):
264264
return True
265265
case (

Lib/test/test_pyrepl/test_utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,22 @@ def test_gen_colors_keyword_highlighting(self):
125125
("import", "keyword"),
126126
],
127127
),
128+
(
129+
"match +1",
130+
[
131+
("match", "soft_keyword"),
132+
("+", "op"),
133+
("1", "number"),
134+
],
135+
),
136+
(
137+
"match -1",
138+
[
139+
("match", "soft_keyword"),
140+
("-", "op"),
141+
("1", "number"),
142+
],
143+
),
128144
]
129145
for code, expected_highlights in cases:
130146
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)