Skip to content

Commit

Permalink
bpo-34108: Fix double carriage return in 2to3 on Windows (GH-8271) (#…
Browse files Browse the repository at this point in the history
…8275)

* Add test capturing failure.
* Honor newlines as present in the original file.
(cherry picked from commit cafaf04)

Co-authored-by: Jason R. Coombs <[email protected]>
  • Loading branch information
miss-islington and jaraco committed Jul 13, 2018
1 parent 08c1da7 commit cf21d00
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/lib2to3/refactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def write_file(self, new_text, filename, old_text, encoding=None):
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
Expand Down
1 change: 1 addition & 0 deletions Lib/lib2to3/tests/test_refactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ def test_crlf_unchanged(self):
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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove extraneous CR in 2to3 refactor.

0 comments on commit cf21d00

Please sign in to comment.