Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Lib/idlelib/idle_test/test_outwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
9 changes: 9 additions & 0 deletions Lib/idlelib/iomenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions Lib/idlelib/outwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Loading