-
-
Notifications
You must be signed in to change notification settings - Fork 584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import format changes based on line ending type #1566
Comments
From my brief inspection, I believe the issue lies here Line 44 in 6807cfb
with newline="" . From python docs:
I'm not sure if this the exact reason and I would delve a bit deeper when I get time. |
@anirudnits |
For reference, here's how Black appears to solve both issues at once (edited heavily for brevity):
Note that they preserve newlines for output, and use only LF internally (which should give consistent formatting in this case) Actual implementation in Black source code: |
I abandoned my PR for a couple of reasons:
assert api.sort_code_string("import A\n\r\nimportA\n\n") == "import A\r\n\r\nimportA\r\n\n" |
Hi @VakarisZ, I'm sorry you experienced this error! This has been fixed in develop and will be released to PyPI in the 5.8.0 release of isort. To address the thread about how newlines are handled that stemmed from this issue: isort can't do things exactly like Black does because it is streaming based, and doesn't load a full file at once. This is much more efficient and scalable but it does come with some costs. That said, isort does a good job of keeping track of the line separator used for a chunk of imports, and generally uses this information when checking line length - I tracked it down to a single place where the parsed line separator was ignored and \n hard coded, I then added an additional test case to ensure this doesn't pop up again. Thanks! ~Timothy |
Thanks, @timothycrosley, you rock! |
Import
checked with command
python -m isort . -c -l 120 --wl 120
passes on dos line endings, but with unix line endings it fails because it expectsVisually, both line endings look the same, so I'd expect them to be treated the same (either as 1 or as 2 characters).
The text was updated successfully, but these errors were encountered: