Skip to content

Commit

Permalink
Merge pull request #1694 from PyCQA/issue/1566
Browse files Browse the repository at this point in the history
Issue/1566
  • Loading branch information
timothycrosley authored Mar 20, 2021
2 parents 5a0ebba + 404d809 commit 43cfa47
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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")

0 comments on commit 43cfa47

Please sign in to comment.