From 2cc0da91c7f96834a4159518b68d4f7f5caf86e3 Mon Sep 17 00:00:00 2001 From: johnslavik Date: Fri, 5 Jun 2026 19:20:17 +0200 Subject: [PATCH 1/5] Colorize `case +` --- Lib/_pyrepl/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/_pyrepl/utils.py b/Lib/_pyrepl/utils.py index b50426c31ead53..f2837a1b8eb95e 100644 --- a/Lib/_pyrepl/utils.py +++ b/Lib/_pyrepl/utils.py @@ -274,7 +274,7 @@ def is_soft_keyword_used(*tokens: TI | None) -> bool: None | TI(T.NEWLINE) | TI(T.INDENT) | TI(T.DEDENT) | TI(string=":"), TI(string="case"), TI(T.NUMBER | T.STRING | T.FSTRING_START | T.TSTRING_START) - | TI(T.OP, string="(" | "*" | "-" | "[" | "{") + | TI(T.OP, string="(" | "*" | "-" | "+" | "[" | "{") ): return True case ( From d201c138c7064440a2a3dd4695cf52037167fbc3 Mon Sep 17 00:00:00 2001 From: johnslavik Date: Tue, 9 Jun 2026 22:45:33 +0200 Subject: [PATCH 2/5] Add tests for `case +` soft keyword colorization --- Lib/test/test_pyrepl/test_utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Lib/test/test_pyrepl/test_utils.py b/Lib/test/test_pyrepl/test_utils.py index 3c55b6bdaeee9e..2e7fadabdaf651 100644 --- a/Lib/test/test_pyrepl/test_utils.py +++ b/Lib/test/test_pyrepl/test_utils.py @@ -125,6 +125,15 @@ def test_gen_colors_keyword_highlighting(self): ("import", "keyword"), ], ), + # `case` soft keyword with unary +/- operators (gh-145239) + ( + "case +1", + [("case", "soft_keyword"), ("+", "op")], + ), + ( + "case -1", + [("case", "soft_keyword"), ("-", "op")], + ), ] for code, expected_highlights in cases: with self.subTest(code=code): From 6a51383d1fb443ba59dda10d65bf5dec2bfbe58b Mon Sep 17 00:00:00 2001 From: johnslavik Date: Tue, 9 Jun 2026 22:50:46 +0200 Subject: [PATCH 3/5] Fix formatting --- Lib/test/test_pyrepl/test_utils.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_pyrepl/test_utils.py b/Lib/test/test_pyrepl/test_utils.py index 2e7fadabdaf651..a8ebf69163074d 100644 --- a/Lib/test/test_pyrepl/test_utils.py +++ b/Lib/test/test_pyrepl/test_utils.py @@ -125,14 +125,19 @@ def test_gen_colors_keyword_highlighting(self): ("import", "keyword"), ], ), - # `case` soft keyword with unary +/- operators (gh-145239) ( "case +1", - [("case", "soft_keyword"), ("+", "op")], + [ + ("case", "soft_keyword"), + ("+", "op"), + ], ), ( "case -1", - [("case", "soft_keyword"), ("-", "op")], + [ + ("case", "soft_keyword"), + ("-", "op"), + ], ), ] for code, expected_highlights in cases: From 9be9e29a8b44f3fed123246fb012cfefc35ebc2d Mon Sep 17 00:00:00 2001 From: johnslavik Date: Tue, 9 Jun 2026 22:53:04 +0200 Subject: [PATCH 4/5] Remove case - test, keep only case + --- Lib/test/test_pyrepl/test_utils.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Lib/test/test_pyrepl/test_utils.py b/Lib/test/test_pyrepl/test_utils.py index a8ebf69163074d..a472cb667d2478 100644 --- a/Lib/test/test_pyrepl/test_utils.py +++ b/Lib/test/test_pyrepl/test_utils.py @@ -132,13 +132,6 @@ def test_gen_colors_keyword_highlighting(self): ("+", "op"), ], ), - ( - "case -1", - [ - ("case", "soft_keyword"), - ("-", "op"), - ], - ), ] for code, expected_highlights in cases: with self.subTest(code=code): From aaa58a2441727d85fde081f5344b5c8aabd08fe9 Mon Sep 17 00:00:00 2001 From: johnslavik Date: Tue, 9 Jun 2026 23:21:16 +0200 Subject: [PATCH 5/5] Fix test --- Lib/test/test_pyrepl/test_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_pyrepl/test_utils.py b/Lib/test/test_pyrepl/test_utils.py index a472cb667d2478..0b873d32b62b5d 100644 --- a/Lib/test/test_pyrepl/test_utils.py +++ b/Lib/test/test_pyrepl/test_utils.py @@ -130,6 +130,7 @@ def test_gen_colors_keyword_highlighting(self): [ ("case", "soft_keyword"), ("+", "op"), + ("1", "number"), ], ), ]