gh-138318, PyREPL: builtins should not be highlighted when used as attribute names (#138319)

This commit is contained in:
yihong 2025-09-08 21:04:22 +08:00 committed by GitHub
parent 921f61bd82
commit 7a3bca50e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 2 deletions

View file

@ -1,6 +1,6 @@
from unittest import TestCase
from _pyrepl.utils import str_width, wlen, prev_next_window
from _pyrepl.utils import str_width, wlen, prev_next_window, gen_colors
class TestUtils(TestCase):
@ -60,3 +60,25 @@ def gen_raise():
self.assertEqual(next(pnw), (3, 4, None))
with self.assertRaises(ZeroDivisionError):
next(pnw)
def test_gen_colors_keyword_highlighting(self):
cases = [
# no highlights
("a.set", [(".", "op")]),
("obj.list", [(".", "op")]),
("obj.match", [(".", "op")]),
("b. \\\n format", [(".", "op")]),
# highlights
("set", [("set", "builtin")]),
("list", [("list", "builtin")]),
(" \n dict", [("dict", "builtin")]),
]
for code, expected_highlights in cases:
with self.subTest(code=code):
colors = list(gen_colors(code))
# Extract (text, tag) pairs for comparison
actual_highlights = []
for color in colors:
span_text = code[color.span.start:color.span.end + 1]
actual_highlights.append((span_text, color.tag))
self.assertEqual(actual_highlights, expected_highlights)