https://github.com/python/cpython/commit/d100c642752d88e202081156525c906c6d20470d
commit: d100c642752d88e202081156525c906c6d20470d
branch: main
author: sidlovescoding <[email protected]>
committer: StanFromIreland <[email protected]>
date: 2026-11-11T19:17:02Z
summary:

gh-141998: Do not syntax highlight text read by `input()` in the REPL (#161790)

Co-authored-by: Stan Ulbrych <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-11-08-19-29-54.gh-issue-141998.8vum0w.rst
M Lib/_pyrepl/readline.py
M Lib/test/test_pyrepl/test_pyrepl.py

diff --git a/Lib/_pyrepl/readline.py b/Lib/_pyrepl/readline.py
index 4232a868a34e9ad..fbc0f5926ea16b4 100644
--- a/Lib/_pyrepl/readline.py
+++ b/Lib/_pyrepl/readline.py
@@ -377,7 +377,7 @@ def input(self, prompt: object = "") -> str:
         prompt_str = str(prompt)
         reader.ps1 = prompt_str
         sys.audit("builtins.input", prompt_str)
-        with reader.suspend_history_writes():
+        with reader.suspend_history_writes(), reader.suspend_colorization():
             result = reader.readline(startup_hook=self.startup_hook)
         sys.audit("builtins.input/result", result)
         return result
diff --git a/Lib/test/test_pyrepl/test_pyrepl.py 
b/Lib/test/test_pyrepl/test_pyrepl.py
index 1828fd735669d54..c11c759f559affa 100644
--- a/Lib/test/test_pyrepl/test_pyrepl.py
+++ b/Lib/test/test_pyrepl/test_pyrepl.py
@@ -732,6 +732,16 @@ def test_input_does_not_modify_history(self):
         self.assertEqual(wrapper.input(), "new input")
         self.assertEqual(reader.history, ["previous input"])
 
+    def test_input_is_not_syntax_highlighted(self):
+        reader = self.prepare_reader(code_to_events("def f(): pass\n"))
+        reader.can_colorize = True
+        reader.gen_colors = Mock(return_value=())
+        wrapper = _ReadlineWrapper(f_in=None, f_out=None, reader=reader)
+
+        self.assertEqual(wrapper.input(), "def f(): pass")
+        reader.gen_colors.assert_not_called()
+        self.assertTrue(reader.can_colorize)
+
     def test_input_error_does_not_modify_history(self):
         for text, exception in (
             ("partial input\x03", KeyboardInterrupt),
diff --git 
a/Misc/NEWS.d/next/Library/2026-11-08-19-29-54.gh-issue-141998.8vum0w.rst 
b/Misc/NEWS.d/next/Library/2026-11-08-19-29-54.gh-issue-141998.8vum0w.rst
new file mode 100644
index 000000000000000..633c27d55175a3d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-11-08-19-29-54.gh-issue-141998.8vum0w.rst
@@ -0,0 +1,2 @@
+Do not syntax highlight text typed in response to :func:`input` in the
+:term:`REPL`.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to