]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-136924: Suspend REPL colorizing when in a REPL interactive command (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 3 Jan 2026 14:34:47 +0000 (15:34 +0100)
committerGitHub <noreply@github.com>
Sat, 3 Jan 2026 14:34:47 +0000 (15:34 +0100)
(cherry picked from commit 2c39b9d2f2ed8fb719d89f895dba114fb9096826)

Co-authored-by: Olga Matoula <olgamatoula@gmail.com>
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 ff1bdab9fea0785d61740367a10809b5ae7497b3..6508f0233b963ad2fe3b0d6f5775d9425f5efe3d 100644 (file)
@@ -125,7 +125,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.