Skip to content

Commit 2c39b9d

Browse files
olgarithmsambv
andauthored
gh-136924: Suspend REPL colorizing when in a REPL interactive command (GH-136926)
Co-authored-by: Łukasz Langa <[email protected]>
1 parent 6d05e55 commit 2c39b9d

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

Lib/_pyrepl/reader.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,16 @@ def suspend(self) -> SimpleContextManager:
619619
setattr(self, arg, prev_state[arg])
620620
self.prepare()
621621

622+
@contextmanager
623+
def suspend_colorization(self) -> SimpleContextManager:
624+
try:
625+
old_can_colorize = self.can_colorize
626+
self.can_colorize = False
627+
yield
628+
finally:
629+
self.can_colorize = old_can_colorize
630+
631+
622632
def finish(self) -> None:
623633
"""Called when a command signals that we're finished."""
624634
pass

Lib/_pyrepl/simple_interact.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def maybe_run_command(statement: str) -> bool:
124124
command = REPL_COMMANDS[statement]
125125
if callable(command):
126126
# Make sure that history does not change because of commands
127-
with reader.suspend_history():
127+
with reader.suspend_history(), reader.suspend_colorization():
128128
command()
129129
return True
130130
return False
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The interactive help mode in the :term:`REPL` no longer incorrectly syntax
2+
highlights text input as Python code. Contributed by Olga Matoula.

0 commit comments

Comments
 (0)