]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-136924: Suspend REPL colorizing when in a REPL interactive command (GH-136926)
authorOlga Matoula <olgamatoula@gmail.com>
Sat, 3 Jan 2026 13:35:34 +0000 (15:35 +0200)
committerGitHub <noreply@github.com>
Sat, 3 Jan 2026 13:35:34 +0000 (14:35 +0100)
Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Lib/_pyrepl/reader.py
Lib/_pyrepl/simple_interact.py
Misc/NEWS.d/next/Core_and_Builtins/2026-01-03-14-02-11.gh-issue-136924.UMgdPn.rst [new file with mode: 0644]

index 0ebd9162eca4bbae682c840adb42f635de156994..9ab92f64d1ef63dddc245c2887929cac201e8cfe 100644 (file)
@@ -619,6 +619,16 @@ class Reader:
                 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
index 3b0debf2ba037bf64f2df9e53457bb152e187f29..0da9f91baf6cfc76e9715529f35eaf76ceac41b0 100644 (file)
@@ -124,7 +124,7 @@ def run_multiline_interactive_console(
         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 (file)
index 0000000..b147b05
--- /dev/null
@@ -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.