Skip to content

Commit 6eafcae

Browse files
miss-islingtonolgarithmsambv
authored
[3.14] gh-136924: Suspend REPL colorizing when in a REPL interactive command (GH-136926) (GH-143390)
(cherry picked from commit 2c39b9d) Co-authored-by: Olga Matoula <[email protected]> Co-authored-by: Łukasz Langa <[email protected]>
1 parent 6610832 commit 6eafcae

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
@@ -125,7 +125,7 @@ def maybe_run_command(statement: str) -> bool:
125125
command = REPL_COMMANDS[statement]
126126
if callable(command):
127127
# Make sure that history does not change because of commands
128-
with reader.suspend_history():
128+
with reader.suspend_history(), reader.suspend_colorization():
129129
command()
130130
return True
131131
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)