From a1f2782e4d825a54b2eec698b3520e30526a343f Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Fri, 19 Mar 2021 23:33:56 -0700 Subject: [PATCH 1/4] Create failing test for issue #1566 --- tests/unit/test_regressions.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/unit/test_regressions.py b/tests/unit/test_regressions.py index 9f1755254..4cd8a3fac 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 + ) From 844c85c36108937ec1962a94d54dba634d568d00 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Fri, 19 Mar 2021 23:34:38 -0700 Subject: [PATCH 2/4] Add changelog entry for issue #1566 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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. From 0ee873365c722d5eea95e0e838b771f4b06a61e1 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Sat, 20 Mar 2021 00:06:02 -0700 Subject: [PATCH 3/4] Fix test to ensure output is the same --- tests/unit/test_regressions.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/test_regressions.py b/tests/unit/test_regressions.py index 4cd8a3fac..26517598c 100644 --- a/tests/unit/test_regressions.py +++ b/tests/unit/test_regressions.py @@ -1610,12 +1610,12 @@ def test_isort_shouldnt_move_noqa_comment_issue_1594(): def test_isort_correctly_handles_unix_vs_linux_newlines_issue_1566(): - IMPORT_STATEMENT = ( + 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 - ) + assert isort.code(import_statement, line_length=120) == isort.code( + import_statement.replace("\n", "\r\n"), line_length=120 + ).replace("\r\n", "\n") From 404d809a692d68db0f36016b91171befec48be81 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Sat, 20 Mar 2021 00:06:38 -0700 Subject: [PATCH 4/4] Fix issue #1566: Fixed single location parsed line separator isn't used --- isort/output.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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)