https://github.com/python/cpython/commit/2c39b9d2f2ed8fb719d89f895dba114fb9096826
commit: 2c39b9d2f2ed8fb719d89f895dba114fb9096826
branch: main
author: Olga Matoula <[email protected]>
committer: ambv <[email protected]>
date: 2026-01-03T14:35:34+01:00
summary:

gh-136924: Suspend REPL colorizing when in a REPL interactive command 
(GH-136926)

Co-authored-by: Ɓukasz Langa <[email protected]>

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-01-03-14-02-11.gh-issue-136924.UMgdPn.rst
M Lib/_pyrepl/reader.py
M Lib/_pyrepl/simple_interact.py

diff --git a/Lib/_pyrepl/reader.py b/Lib/_pyrepl/reader.py
index 0ebd9162eca4bb..9ab92f64d1ef63 100644
--- a/Lib/_pyrepl/reader.py
+++ b/Lib/_pyrepl/reader.py
@@ -619,6 +619,16 @@ def suspend(self) -> SimpleContextManager:
                 setattr(self, arg, prev_state[arg])
             self.prepare()
 
+    @contextmanager
+    def suspend_colorization(self) -> SimpleContextManager:
+        try:
+            old_can_colorize = self.can_colorize
+            self.can_colorize = False
+            yield
+        finally:
+            self.can_colorize = old_can_colorize
+
+
     def finish(self) -> None:
         """Called when a command signals that we're finished."""
         pass
diff --git a/Lib/_pyrepl/simple_interact.py b/Lib/_pyrepl/simple_interact.py
index 3b0debf2ba037b..0da9f91baf6cfc 100644
--- a/Lib/_pyrepl/simple_interact.py
+++ b/Lib/_pyrepl/simple_interact.py
@@ -124,7 +124,7 @@ def maybe_run_command(statement: str) -> bool:
         command = REPL_COMMANDS[statement]
         if callable(command):
             # Make sure that history does not change because of commands
-            with reader.suspend_history():
+            with reader.suspend_history(), reader.suspend_colorization():
                 command()
             return True
         return False
diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2026-01-03-14-02-11.gh-issue-136924.UMgdPn.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-01-03-14-02-11.gh-issue-136924.UMgdPn.rst
new file mode 100644
index 00000000000000..b147b05bf8212b
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-01-03-14-02-11.gh-issue-136924.UMgdPn.rst
@@ -0,0 +1,2 @@
+The interactive help mode in the :term:`REPL` no longer incorrectly syntax
+highlights text input as Python code. Contributed by Olga Matoula.

_______________________________________________
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