From ec24349db3d11e9ba9a4c2b343a3ed77764bfedc Mon Sep 17 00:00:00 2001 From: Olga Matoula Date: Sun, 20 Jul 2025 16:20:10 +0200 Subject: [PATCH 1/2] Suspend REPL colorizing when in a REPL interactive command --- Lib/_pyrepl/reader.py | 10 ++++++++++ Lib/_pyrepl/simple_interact.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) 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 965b853c34b392..47eb2db74054bd 100644 --- a/Lib/_pyrepl/simple_interact.py +++ b/Lib/_pyrepl/simple_interact.py @@ -125,7 +125,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 From b488293a5da4e7f8860382fb6f462e70d675eeb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Sat, 3 Jan 2026 14:02:23 +0100 Subject: [PATCH 2/2] Add Blurb --- .../2026-01-03-14-02-11.gh-issue-136924.UMgdPn.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-01-03-14-02-11.gh-issue-136924.UMgdPn.rst 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.