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

(cherry picked from commit 2c39b9d2f2)

Co-authored-by: Olga Matoula <olgamatoula@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
Miss Islington (bot) 2026-01-03 15:34:47 +01:00 committed by GitHub
parent 661083297f
commit 6eafcaee64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -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.