Skip to content

Commit b701ca1

Browse files
committed
Highlight match statements after dedents
1 parent fb7e209 commit b701ca1

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

‎Lib/_pyrepl/utils.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,14 @@ def is_soft_keyword_used(*tokens: TI | None) -> bool:
266266
trace("is_soft_keyword_used{t}", t=tokens)
267267
match tokens:
268268
case (
269-
None | TI(T.NEWLINE | T.NL | T.INDENT) | TI(string=":"),
269+
None | TI(T.NEWLINE | T.NL | T.INDENT | T.DEDENT) | TI(string=":"),
270270
TI(string="match"),
271271
TI(T.NUMBER | T.STRING | T.FSTRING_START | T.TSTRING_START)
272272
| TI(T.OP, string="(" | "*" | "-" | "+" | "[" | "{" | "~" | "...")
273273
):
274274
return True
275275
case (
276-
None | TI(T.NEWLINE | T.NL | T.INDENT) | TI(string=":"),
276+
None | TI(T.NEWLINE | T.NL | T.INDENT | T.DEDENT) | TI(string=":"),
277277
TI(string="match"),
278278
TI(T.NAME, string=s)
279279
):

‎Lib/test/test_pyrepl/test_utils.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,21 @@ def test_gen_colors_soft_keywords_after_blank_lines(self):
197197
]
198198
self.assertEqual(actual, expected)
199199

200+
def test_gen_colors_match_after_dedent(self):
201+
for subject in ("-1", "value"):
202+
for separator in ("", "\n", "# comment\n"):
203+
code = (
204+
"if x:\n pass\n"
205+
f"{separator}match {subject}:\n case _: pass"
206+
)
207+
with self.subTest(code=code):
208+
actual = [
209+
code[color.span.start:color.span.end + 1]
210+
for color in gen_colors(code)
211+
if color.tag == "soft_keyword"
212+
]
213+
self.assertEqual(actual, ["match", "case", "_"])
214+
200215
def test_gen_colors_soft_keyword_names_in_brackets(self):
201216
for opening, closing in ("()", "[]", "{}"):
202217
for name in ("match", "case"):
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
Fix soft keyword highlighting after blank and comment-only lines in the
2-
:ref:`interactive shell <tut-interactive>`. Patch by Bartosz Sławecki.
1+
Fix soft keyword highlighting after blank lines, comment-only lines, and
2+
dedents in the :ref:`interactive shell <tut-interactive>`. Patch by Bartosz
3+
Sławecki.

0 commit comments

Comments
 (0)