Skip to content

Commit a625cec

Browse files
committed
fix: address comments
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
1 parent 72574f5 commit a625cec

3 files changed

Lines changed: 12 additions & 19 deletions

File tree

Lib/_pyrepl/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,10 @@ def gen_colors_from_token_stream(
208208
):
209209
span = Span.from_token(token, line_lengths)
210210
yield ColorSpan(span, "soft_keyword")
211-
elif (token.string in BUILTINS
212-
and not (prev_token and prev_token.type == T.OP and prev_token.string == ".")):
211+
elif (
212+
token.string in BUILTINS
213+
and not (prev_token and prev_token.type == T.OP
214+
and prev_token.string == ".")):
213215
span = Span.from_token(token, line_lengths)
214216
yield ColorSpan(span, "builtin")
215217

Lib/test/test_pyrepl/test_utils.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,32 +62,21 @@ def gen_raise():
6262
next(pnw)
6363

6464
def test_gen_colors_keyword_highlighting(self):
65-
no_highlight_cases = [
65+
cases = [
66+
# no highlights
6667
("a.set", [(".", "op")]),
6768
("obj.list", [(".", "op")]),
6869
("obj.match", [(".", "op")]),
69-
]
70-
for code, expected_highlights in no_highlight_cases:
71-
with self.subTest(code=code):
72-
colors = list(gen_colors(code))
73-
# Extract (text, tag) pairs for comparison
74-
actual_highlights = []
75-
for color in colors:
76-
span_text = code[color.span.start:color.span.end + 1]
77-
actual_highlights.append((span_text, color.tag))
78-
self.assertEqual(actual_highlights, expected_highlights,
79-
f"In '{code}', expected {expected_highlights}, got {actual_highlights}")
80-
highlight_cases = [
70+
# highlights
8171
("set", [("set", "builtin")]),
8272
("list", [("list", "builtin")]),
8373
]
84-
for code, expected_highlights in highlight_cases:
74+
for code, expected_highlights in cases:
8575
with self.subTest(code=code):
8676
colors = list(gen_colors(code))
8777
# Extract (text, tag) pairs for comparison
8878
actual_highlights = []
8979
for color in colors:
9080
span_text = code[color.span.start:color.span.end + 1]
9181
actual_highlights.append((span_text, color.tag))
92-
self.assertEqual(actual_highlights, expected_highlights,
93-
f"In '{code}', expected {expected_highlights}, got {actual_highlights}")
82+
self.assertEqual(actual_highlights, expected_highlights)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
fix: xxx.builtins the builtins keyword should not highlight in new repl
1+
The default REPL now avoids highlighting built-in names (for instance :class:`set`
2+
or :func:`format`) when they are used as attribute names (for instance in ``value.set``
3+
or ``text.format``).

0 commit comments

Comments
 (0)