diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d0a99b2c..4a805715c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/isort/output.py b/isort/output.py index 13f72a3d5..61c2e30ec 100644 --- a/isort/output.py +++ b/isort/output.py @@ -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) diff --git a/tests/unit/test_regressions.py b/tests/unit/test_regressions.py index 9f1755254..26517598c 100644 --- a/tests/unit/test_regressions.py +++ b/tests/unit/test_regressions.py @@ -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")