Skip to content

Commit

Permalink
Fix #1575: Leading space is removed from wrong line
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Nov 3, 2020
1 parent 3424d83 commit 1dc62ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
10 changes: 7 additions & 3 deletions isort/core.py
Expand Up @@ -275,7 +275,7 @@ def write(self, *a, **kw):
):
cimport_statement = True

if cimport_statement != cimports or (new_indent != indent and import_section):
if cimport_statement != cimports and import_section:
if import_section:
next_cimports = cimport_statement
next_import_section = import_statement
Expand All @@ -284,8 +284,12 @@ def write(self, *a, **kw):
line = ""
else:
cimports = cimport_statement

indent = new_indent
else:
if new_indent != indent:
if import_section:
import_statement = import_statement.lstrip()
else:
indent = new_indent
import_section += import_statement
else:
not_imports = True
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_ticketed_features.py
Expand Up @@ -876,3 +876,18 @@ def test_api_to_allow_custom_diff_and_output_stream_1583(capsys, tmpdir):

isort_output.seek(0)
assert isort_output.read().splitlines() == ["import a", "import b"]


def test_autofix_mixed_indent_imports_1575():
"""isort should automatically fix import statements that are sent in
with incorrect mixed indentation.
See: https://github.com/PyCQA/isort/issues/1575
"""
assert isort.code("""
import os
import os
""") == """
import os
"""


0 comments on commit 1dc62ff

Please sign in to comment.