Author jaraco
Recipients benjamin.peterson, bialix, eric.araujo, jaraco
Date 2017-12-08.19:25:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This issue affected me today. I'm editing a codebase that has mixed line endings in different files. I'd like to patch for Python 3 support without changing line endings. Even invoking a single fixer (print), the line endings mutate. Since I'm running on macOS, the files with CRLF get LF line endings.

Answers [in this question]( suggest the mutation can be suppressed by altering the _to_system_newlines function, but the proposed fix has no effect on the Python 3.6 version of this routine.

I thought I'd encountered this issue before, but I realized after searching that I was thinking of issue10639, which may present a model for retaining the newlines when refactoring the code.

I found I was able to work around the issue by putting in my current directory:

import lib2to3.refactor
import runpy
import functools

if __name__ == '__main__':
	lib2to3.refactor._open_with_encoding = functools.partial(open, newline='')

And invoking `python -m lib2to3-clean` instead of `-m lib2to3`. The addition of newline='' follows the [guidance in the docs]( on how to avoid mutating newlines.

I've released this functionality in [jaraco.develop 4.0]( so others can readily invoke it with `rwt jaraco.develop -- -m jaraco.develop.lib2to3`.
Date User Action Args
2017-12-08 19:25:24jaracosetrecipients: + jaraco, bialix, benjamin.peterson, eric.araujo
2017-12-08 19:25:24jaracosetmessageid: <>
2017-12-08 19:25:24jaracolinkissue11594 messages
2017-12-08 19:25:24jaracocreate