From d4c8b974d9e0b888e0ffdef8ee8bfa053eae3d8c Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 17 Sep 2026 22:27:39 +0300 Subject: [PATCH 1/4] gh-64007: Do not colorize input for input() in the IDLE Shell 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. --- Lib/idlelib/idle_test/test_pyshell.py | 35 +++++++++++++++++++ Lib/idlelib/pyshell.py | 12 +++++-- ...-17-21-00-00.gh-issue-64007.inputcolor.rst | 2 ++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/IDLE/2026-09-17-21-00-00.gh-issue-64007.inputcolor.rst diff --git a/Lib/idlelib/idle_test/test_pyshell.py b/Lib/idlelib/idle_test/test_pyshell.py index dec81bdbbccd67..304da4faeb8c0e 100644 --- a/Lib/idlelib/idle_test/test_pyshell.py +++ b/Lib/idlelib/idle_test/test_pyshell.py @@ -69,6 +69,41 @@ def test_init(self): ## self.assertIsInstance(ps, pyshell.PyShell) +class PyShellTest(unittest.TestCase): + + @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 997b91e53327d7..5444e705a14efe 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 00000000000000..2e77f55751fa31 --- /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. From ca5d37772675d00c7e43bb816f79de50d0bf18ac Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sun, 20 Sep 2026 16:25:52 -0400 Subject: [PATCH 2/4] Rename test class -- terryjreedy --- Lib/idlelib/idle_test/test_pyshell.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/idlelib/idle_test/test_pyshell.py b/Lib/idlelib/idle_test/test_pyshell.py index 304da4faeb8c0e..4bc8239c19f42c 100644 --- a/Lib/idlelib/idle_test/test_pyshell.py +++ b/Lib/idlelib/idle_test/test_pyshell.py @@ -69,7 +69,8 @@ def test_init(self): ## self.assertIsInstance(ps, pyshell.PyShell) -class PyShellTest(unittest.TestCase): +class InputStatementlTest(unittest.TestCase): + # Test handling of response to input statements in user code. @classmethod def setUpClass(cls): From 6a7e0c2916b66b86724f2980c1ad61cb29cd5892 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sun, 20 Sep 2026 16:31:33 -0400 Subject: [PATCH 3/4] Update Lib/idlelib/idle_test/test_pyshell.py --- Lib/idlelib/idle_test/test_pyshell.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/idlelib/idle_test/test_pyshell.py b/Lib/idlelib/idle_test/test_pyshell.py index 4bc8239c19f42c..d5f6425a3b83e4 100644 --- a/Lib/idlelib/idle_test/test_pyshell.py +++ b/Lib/idlelib/idle_test/test_pyshell.py @@ -69,6 +69,7 @@ def test_init(self): ## self.assertIsInstance(ps, pyshell.PyShell) + class InputStatementlTest(unittest.TestCase): # Test handling of response to input statements in user code. From fdd73606dc8c80913fbd1535778a1d9f5f4b58ec Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sun, 20 Sep 2026 16:36:46 -0400 Subject: [PATCH 4/4] Update Lib/idlelib/idle_test/test_pyshell.py --- Lib/idlelib/idle_test/test_pyshell.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/idlelib/idle_test/test_pyshell.py b/Lib/idlelib/idle_test/test_pyshell.py index d5f6425a3b83e4..009adae3dcbe8c 100644 --- a/Lib/idlelib/idle_test/test_pyshell.py +++ b/Lib/idlelib/idle_test/test_pyshell.py @@ -106,6 +106,7 @@ def test_input_not_colorized(self): self.assertEqual(len(text.tag_ranges('KEYWORD')), 4) + class PyShellRemoveLastNewlineAndSurroundingWhitespaceTest(unittest.TestCase): regexp = pyshell.PyShell._last_newline_re