Skip to content
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

Issue/1566 #1694

Merged
merged 4 commits into from Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@ Find out more about isort's release policy [here](https://pycqa.github.io/isort/
- Fixed #1631: as import comments can in some cases be duplicated.
- Fixed #1667: extra newline added with float-to-top, after skip, in some cases.
- Fixed #1594: incorrect placement of noqa comments with multiple from imports.
- Fixed #1566: in some cases different length limits for dos based line endings.
- Implemented #1648: Export MyPY type hints.
- Implemented #1641: Identified import statements now return runnable code.
- Implemented #1661: Added "wemake" profile.
Expand Down
8 changes: 7 additions & 1 deletion isort/output.py
Expand Up @@ -504,7 +504,13 @@ def _with_from_imports(
config=config,
multi_line_output=wrap.Modes.VERTICAL_GRID, # type: ignore
)
if max(len(x) for x in import_statement.split("\n")) > config.line_length:
if (
max(
len(import_line)
for import_line in import_statement.split(parsed.line_separator)
)
> config.line_length
):
import_statement = other_import_statement
if not do_multiline_reformat and len(import_statement) > config.line_length:
import_statement = wrap.line(import_statement, parsed.line_separator, config)
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_regressions.py
Expand Up @@ -1607,3 +1607,15 @@ def test_isort_shouldnt_move_noqa_comment_issue_1594():
)
"""
)


def test_isort_correctly_handles_unix_vs_linux_newlines_issue_1566():
import_statement = (
"from impacket.smb3structs import (\n"
"SMB2_CREATE, SMB2_FLAGS_DFS_OPERATIONS, SMB2_IL_IMPERSONATION, "
"SMB2_OPLOCK_LEVEL_NONE, SMB2Create,"
"\nSMB2Create_Response, SMB2Packet)\n"
)
assert isort.code(import_statement, line_length=120) == isort.code(
import_statement.replace("\n", "\r\n"), line_length=120
).replace("\r\n", "\n")