summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2025-09-29 20:11:41 (GMT)
committerGitHub <noreply@github.com>2025-09-29 20:11:41 (GMT)
commit4372a05ab0b4ee2b3c5bf13e07508653f257e418 (patch)
tree854af6e3b8d59a9070baecf713d8594b473b0aae
parentaf694375ea51bbf79db4218900ce73bf79b8416e (diff)
downloadcpython-4372a05ab0b4ee2b3c5bf13e07508653f257e418.zip
cpython-4372a05ab0b4ee2b3c5bf13e07508653f257e418.tar.gz
cpython-4372a05ab0b4ee2b3c5bf13e07508653f257e418.tar.bz2
[3.14] gh-134953: Make the True/False/None check more efficient (GH-138931) (#138939)
-rw-r--r--Lib/_pyrepl/utils.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/Lib/_pyrepl/utils.py b/Lib/_pyrepl/utils.py
index d32fce5..99b5c5a 100644
--- a/Lib/_pyrepl/utils.py
+++ b/Lib/_pyrepl/utils.py
@@ -20,6 +20,7 @@ ANSI_ESCAPE_SEQUENCE = re.compile(r"\x1b\[[ -@]*[A-~]")
ZERO_WIDTH_BRACKET = re.compile(r"\x01.*?\x02")
ZERO_WIDTH_TRANS = str.maketrans({"\x01": "", "\x02": ""})
IDENTIFIERS_AFTER = {"def", "class"}
+KEYWORD_CONSTANTS = {"True", "False", "None"}
BUILTINS = {str(name) for name in dir(builtins) if not name.startswith('_')}
@@ -196,12 +197,12 @@ def gen_colors_from_token_stream(
is_def_name = False
span = Span.from_token(token, line_lengths)
yield ColorSpan(span, "definition")
- elif token.string in ("True", "False", "None"):
- span = Span.from_token(token, line_lengths)
- yield ColorSpan(span, "keyword_constant")
elif keyword.iskeyword(token.string):
+ span_cls = "keyword"
+ if token.string in KEYWORD_CONSTANTS:
+ span_cls = "keyword_constant"
span = Span.from_token(token, line_lengths)
- yield ColorSpan(span, "keyword")
+ yield ColorSpan(span, span_cls)
if token.string in IDENTIFIERS_AFTER:
is_def_name = True
elif (