]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-34108: Fix double carriage return in 2to3 on Windows (#8271)
authorJason R. Coombs <jaraco@jaraco.com>
Fri, 13 Jul 2018 15:26:03 +0000 (11:26 -0400)
committerGitHub <noreply@github.com>
Fri, 13 Jul 2018 15:26:03 +0000 (11:26 -0400)
* Add test capturing failure.
* Honor newlines as present in the original file.

Lib/lib2to3/refactor.py
Lib/lib2to3/tests/test_refactor.py
Misc/NEWS.d/next/Library/2018-07-13-08-44-52.bpo-34108.RjobUC.rst [new file with mode: 0644]

index 7c4e0649975cecb90241edf60d6daeec9eb82e55..7841b99a5cd4c1ee7dcc48b405a1c8edb4340739 100644 (file)
@@ -514,7 +514,7 @@ class RefactoringTool(object):
         set.
         """
         try:
-            fp = io.open(filename, "w", encoding=encoding)
+            fp = io.open(filename, "w", encoding=encoding, newline='')
         except OSError as err:
             self.log_error("Can't create %s: %s", filename, err)
             return
index f3059a93113b1cb1b91dc7c5c779dd176c9dd5cd..9e3b8fbb90b2f3b0888fe54d0f08589c46290e91 100644 (file)
@@ -300,6 +300,7 @@ from __future__ import print_function"""
         old, new = self.refactor_file(fn)
         self.assertIn(b"\r\n", old)
         self.assertIn(b"\r\n", new)
+        self.assertNotIn(b"\r\r\n", new)
 
     def test_refactor_docstring(self):
         rt = self.rt()
diff --git a/Misc/NEWS.d/next/Library/2018-07-13-08-44-52.bpo-34108.RjobUC.rst b/Misc/NEWS.d/next/Library/2018-07-13-08-44-52.bpo-34108.RjobUC.rst
new file mode 100644 (file)
index 0000000..1021f98
--- /dev/null
@@ -0,0 +1 @@
+Remove extraneous CR in 2to3 refactor.