Skip to content

Commit 4372a05

Browse files
[3.14] gh-134953: Make the True/False/None check more efficient (GH-138931) (#138939)
1 parent af69437 commit 4372a05

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Lib/_pyrepl/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
ZERO_WIDTH_BRACKET = re.compile(r"\x01.*?\x02")
2121
ZERO_WIDTH_TRANS = str.maketrans({"\x01": "", "\x02": ""})
2222
IDENTIFIERS_AFTER = {"def", "class"}
23+
KEYWORD_CONSTANTS = {"True", "False", "None"}
2324
BUILTINS = {str(name) for name in dir(builtins) if not name.startswith('_')}
2425

2526

@@ -196,12 +197,12 @@ def gen_colors_from_token_stream(
196197
is_def_name = False
197198
span = Span.from_token(token, line_lengths)
198199
yield ColorSpan(span, "definition")
199-
elif token.string in ("True", "False", "None"):
200-
span = Span.from_token(token, line_lengths)
201-
yield ColorSpan(span, "keyword_constant")
202200
elif keyword.iskeyword(token.string):
201+
span_cls = "keyword"
202+
if token.string in KEYWORD_CONSTANTS:
203+
span_cls = "keyword_constant"
203204
span = Span.from_token(token, line_lengths)
204-
yield ColorSpan(span, "keyword")
205+
yield ColorSpan(span, span_cls)
205206
if token.string in IDENTIFIERS_AFTER:
206207
is_def_name = True
207208
elif (

0 commit comments

Comments
 (0)