https://github.com/python/cpython/commit/811acc85d5b001e0bef6ac2e6b499e7c4f149262
commit: 811acc85d5b001e0bef6ac2e6b499e7c4f149262
branch: main
author: Ɓukasz Langa <[email protected]>
committer: ambv <[email protected]>
date: 2025-09-15T18:27:37+02:00
summary:

gh-134953: Make the True/False/None check more efficient (GH-138931)

files:
M Lib/_pyrepl/utils.py

diff --git a/Lib/_pyrepl/utils.py b/Lib/_pyrepl/utils.py
index 2ffd547f99d7c5..64708e843b685b 100644
--- a/Lib/_pyrepl/utils.py
+++ b/Lib/_pyrepl/utils.py
@@ -20,6 +20,7 @@
 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 (

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to