]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-65339: Save IDLE Shell and Output windows as text by default (#152742)
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 1 Jul 2026 20:36:34 +0000 (23:36 +0300)
committerGitHub <noreply@github.com>
Wed, 1 Jul 2026 20:36:34 +0000 (16:36 -0400)
Their content is not Python source, so the Save As dialog now lists text
files first and defaults to a ".txt" extension.

Lib/idlelib/idle_test/test_outwin.py
Lib/idlelib/iomenu.py
Lib/idlelib/outwin.py
Misc/NEWS.d/next/IDLE/2026-07-01-17-00-00.gh-issue-65339.oUtTxt.rst [new file with mode: 0644]

index 0f13363f84f36107283d074ba7ed208f288e5eea..00a7432b90887326042299c2ed225a9d83c31c85 100644 (file)
@@ -41,6 +41,13 @@ class OutputWindowTest(unittest.TestCase):
         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())
 
index fc502f7fde178089dc09206986d4a1ff383c4a6c..9560aaa2da0c4244c4aa56c6c5415b82b69a0308 100644 (file)
@@ -384,7 +384,16 @@ class IOBinding:
         ("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")
index 8baa657550de948ab5ef215af3d1e21b24f936c0..f7e92bb8ac0c77669d2be5f6f1ffd3bd47c689e7 100644 (file)
@@ -78,6 +78,10 @@ class OutputWindow(EditorWindow):
     def __init__(self, *args):
         EditorWindow.__init__(self, *args)
         self.text.bind("<<goto-file-line>>", 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 (file)
index 0000000..a8b216e
--- /dev/null
@@ -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.