https://github.com/python/cpython/commit/bb81bc8b7aad946e045c870728fc0e92c694b095
commit: bb81bc8b7aad946e045c870728fc0e92c694b095
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: terryjreedy <[email protected]>
date: 2026-09-21T01:17:04Z
summary:

[3.13] gh-64007: Do not colorize response to input() in the IDLE Shell 
(GH-157700) (#157878)

gh-64007: Do not colorize response to input() in the IDLE Shell (GH-157700)

The colorizer treated all text after the I/O mark as code.  Now it
skips it while the Shell reads a line for input(), and the colors of
text typed ahead are removed.

---------
(cherry picked from commit f8bbe696f152d302e7eb3eeb0587a1933cae59fc)

Co-authored-by: Serhiy Storchaka <[email protected]>
Co-authored-by: Terry Jan Reedy <[email protected]>

files:
A Misc/NEWS.d/next/IDLE/2026-09-17-21-00-00.gh-issue-64007.inputcolor.rst
M Lib/idlelib/idle_test/test_pyshell.py
M Lib/idlelib/pyshell.py

diff --git a/Lib/idlelib/idle_test/test_pyshell.py 
b/Lib/idlelib/idle_test/test_pyshell.py
index 0e292e7be87ee48..4aa0ba3a90158a8 100644
--- a/Lib/idlelib/idle_test/test_pyshell.py
+++ b/Lib/idlelib/idle_test/test_pyshell.py
@@ -109,6 +109,42 @@ def test_output_at_prompt(self):
         self.assertEqual(shell.shell_sidebar.line_prompts, {3: '>>>'})
 
 
+class InputStatementlTest(unittest.TestCase):
+    # Test handling of response to input statements in user code.
+
+    @classmethod
+    def setUpClass(cls):
+        requires('gui')
+        cls.root = Tk()
+        cls.root.withdraw()
+        cls.shell = pyshell.PyShell(pyshell.PyShellFileList(cls.root))
+        # As after begin().
+        cls.shell.text.mark_set('iomark', 'insert')
+        cls.shell.text.mark_gravity('iomark', 'left')
+
+    @classmethod
+    def tearDownClass(cls):
+        cls.shell.close()
+        del cls.shell
+        cls.root.destroy()
+        del cls.root
+
+    def test_input_not_colorized(self):
+        # gh-64007: input for input() is not colorized, unlike code.
+        shell = self.shell
+        text = shell.text
+        color = shell.color
+        shell.resetoutput()
+        color.reading = True
+        text.insert('end-1c', 'for x in y')
+        color.recolorize_main()
+        self.assertEqual(text.tag_ranges('KEYWORD'), ())
+        color.reading = False
+        color.notify_range('iomark', 'end')
+        color.recolorize_main()
+        self.assertEqual(len(text.tag_ranges('KEYWORD')), 4)
+
+
 class PyShellRemoveLastNewlineAndSurroundingWhitespaceTest(unittest.TestCase):
     regexp = pyshell.PyShell._last_newline_re
 
diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py
index 12df74f2b71544a..e43a1be2675eaff 100755
--- a/Lib/idlelib/pyshell.py
+++ b/Lib/idlelib/pyshell.py
@@ -335,9 +335,13 @@ def open_shell(self, event=None):
 
 class ModifiedColorDelegator(ColorDelegator):
     "Extend base class: colorizer for the shell window itself"
+    reading = False  # True while the user enters input for input().
+
     def recolorize_main(self):
-        self.tag_remove("TODO", "1.0", "iomark")
-        self.tag_add("SYNC", "1.0", "iomark")
+        # Do not colorize output, nor input for input() (gh-64007).
+        end = "end" if self.reading else "iomark"
+        self.tag_remove("TODO", "1.0", end)
+        self.tag_add("SYNC", "1.0", end)
         ColorDelegator.recolorize_main(self)
 
     def removecolors(self):
@@ -1189,9 +1193,13 @@ def readline(self):
         save = self.reading
         try:
             self.reading = True
+            # Input is not Python code (gh-64007).
+            self.color.reading = True
+            self.color.removecolors()
             self.top.mainloop()  # nested mainloop()
         finally:
             self.reading = save
+            self.color.reading = save
         if self._stop_readline_flag:
             self._stop_readline_flag = False
             return ""
diff --git 
a/Misc/NEWS.d/next/IDLE/2026-09-17-21-00-00.gh-issue-64007.inputcolor.rst 
b/Misc/NEWS.d/next/IDLE/2026-09-17-21-00-00.gh-issue-64007.inputcolor.rst
new file mode 100644
index 000000000000000..2e77f55751fa318
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2026-09-17-21-00-00.gh-issue-64007.inputcolor.rst
@@ -0,0 +1,2 @@
+IDLE no longer applies syntax coloring to the text entered for
+:func:`input` in the Shell.

_______________________________________________
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