From 090dc7f724e3cd35f4ae8876c192f7896d3aa7df Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 23 Jul 2020 08:57:14 +0300 Subject: [PATCH 1/3] bpo-41373: IDLE: Fix saving files loaded with no newlines or mixed newlines --- Lib/idlelib/iomenu.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Lib/idlelib/iomenu.py b/Lib/idlelib/iomenu.py index 74ebefd4208f78..623b1f574a780a 100644 --- a/Lib/idlelib/iomenu.py +++ b/Lib/idlelib/iomenu.py @@ -155,6 +155,17 @@ def loadfile(self, filename): parent=self.text) return False + if not isinstance(eol_convention, str): + # If the file does not contain line separators, it is None. + # If the file contains mixed line separators, it is a tuple. + eol_convention = os.linesep # default + if eol_convention is not None: + tkMessageBox.showwarning("Mixed Newlines", + "Mixed newlines detected.\n" + "The file will be changed on save.", + parent=self.text) + converted = True + self.text.delete("1.0", "end") self.set_filename(None) self.fileencoding = fileencoding From 5c75dd5d52a304ad676754389b2f8457146a6843 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 24 Jul 2020 08:44:04 +0300 Subject: [PATCH 2/3] Address review comment. --- Lib/idlelib/iomenu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/idlelib/iomenu.py b/Lib/idlelib/iomenu.py index 623b1f574a780a..8bb2fa6a6e7939 100644 --- a/Lib/idlelib/iomenu.py +++ b/Lib/idlelib/iomenu.py @@ -158,13 +158,13 @@ def loadfile(self, filename): if not isinstance(eol_convention, str): # If the file does not contain line separators, it is None. # If the file contains mixed line separators, it is a tuple. - eol_convention = os.linesep # default if eol_convention is not None: tkMessageBox.showwarning("Mixed Newlines", "Mixed newlines detected.\n" "The file will be changed on save.", parent=self.text) converted = True + eol_convention = os.linesep # default self.text.delete("1.0", "end") self.set_filename(None) From 550254eb39cd01d004bb4691a0d1e3f8875de69f Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Fri, 24 Jul 2020 17:50:41 -0400 Subject: [PATCH 3/3] blurb --- Misc/NEWS.d/next/IDLE/2020-07-24-17-49-58.bpo-41373.YQIPu_.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/IDLE/2020-07-24-17-49-58.bpo-41373.YQIPu_.rst diff --git a/Misc/NEWS.d/next/IDLE/2020-07-24-17-49-58.bpo-41373.YQIPu_.rst b/Misc/NEWS.d/next/IDLE/2020-07-24-17-49-58.bpo-41373.YQIPu_.rst new file mode 100644 index 00000000000000..b50a72fe676a82 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2020-07-24-17-49-58.bpo-41373.YQIPu_.rst @@ -0,0 +1,3 @@ +Save files loaded with no line ending, as when blank, or different line +endings, by setting its line ending to the system default. Fix regression in +3.8.4 and 3.9.0b4.