From 3942cc02e013a4e6cc5cae835a04ffeffd9d67fa Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 1 Jul 2026 23:36:34 +0300 Subject: [PATCH] gh-65339: Save IDLE Shell and Output windows as text by default (GH-152742) Their content is not Python source, so the Save As dialog now lists text files first and defaults to a ".txt" extension. (cherry picked from commit efcfb1a4e0f4d0d0e33aefccd8373e116e98e3de) Co-authored-by: Serhiy Storchaka --- Lib/idlelib/idle_test/test_outwin.py | 7 +++++++ Lib/idlelib/iomenu.py | 9 +++++++++ Lib/idlelib/outwin.py | 4 ++++ .../IDLE/2026-07-01-17-00-00.gh-issue-65339.oUtTxt.rst | 3 +++ 4 files changed, 23 insertions(+) create mode 100644 Misc/NEWS.d/next/IDLE/2026-07-01-17-00-00.gh-issue-65339.oUtTxt.rst diff --git a/Lib/idlelib/idle_test/test_outwin.py b/Lib/idlelib/idle_test/test_outwin.py index 0f13363f84f361..00a7432b908873 100644 --- a/Lib/idlelib/idle_test/test_outwin.py +++ b/Lib/idlelib/idle_test/test_outwin.py @@ -41,6 +41,13 @@ def test_ispythonsource(self): self.assertFalse(w.ispythonsource('test.txt')) self.assertFalse(w.ispythonsource(__file__)) + def test_save_defaults_to_text(self): + # gh-65339: output is saved as text, not Python source. + io = self.window.io + self.assertEqual(io.defaultextension, '.txt') + # Text files are offered before Python files. + self.assertEqual(io.filetypes[0][0], 'Text files') + def test_window_title(self): self.assertEqual(self.window.top.title(), 'Output' + ' (%s)' % platform.python_version()) diff --git a/Lib/idlelib/iomenu.py b/Lib/idlelib/iomenu.py index fc502f7fde1780..9560aaa2da0c42 100644 --- a/Lib/idlelib/iomenu.py +++ b/Lib/idlelib/iomenu.py @@ -384,7 +384,16 @@ def print_window(self, event): ("All files", "*"), ) + # Output windows (Shell, Output) are not Python source, so they list + # text files first and default to ".txt" (gh-65339). + text_filetypes = ( + ("Text files", "*.txt", "TEXT"), + ("Python files", py_extensions, "TEXT"), + ("All files", "*"), + ) + defaultextension = '.py' if sys.platform == 'darwin' else '' + text_defaultextension = '.txt' def askopenfile(self): dir, base = self.defaultfilename("open") diff --git a/Lib/idlelib/outwin.py b/Lib/idlelib/outwin.py index 8baa657550de94..f7e92bb8ac0c77 100644 --- a/Lib/idlelib/outwin.py +++ b/Lib/idlelib/outwin.py @@ -78,6 +78,10 @@ class OutputWindow(EditorWindow): def __init__(self, *args): EditorWindow.__init__(self, *args) self.text.bind("<>", self.goto_file_line) + # Output is not Python source, so save it as text by default + # (gh-65339). + self.io.filetypes = self.io.text_filetypes + self.io.defaultextension = self.io.text_defaultextension # Customize EditorWindow def ispythonsource(self, filename): diff --git a/Misc/NEWS.d/next/IDLE/2026-07-01-17-00-00.gh-issue-65339.oUtTxt.rst b/Misc/NEWS.d/next/IDLE/2026-07-01-17-00-00.gh-issue-65339.oUtTxt.rst new file mode 100644 index 00000000000000..a8b216e86dc8d7 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2026-07-01-17-00-00.gh-issue-65339.oUtTxt.rst @@ -0,0 +1,3 @@ +Saving the IDLE Shell or an Output window now defaults to a ``.txt`` +extension and lists text files before Python files, since their content is +not Python source.