Skip to content

Commit

Permalink
Fix new_indent behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Nov 4, 2020
1 parent 1dc62ff commit 69f2a35
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion isort/core.py
Expand Up @@ -246,6 +246,7 @@ def write(self, *a, **kw):
):
import_section += line
elif stripped_line.startswith(IMPORT_START_IDENTIFIERS):
did_contain_imports = contains_imports
contains_imports = True

new_indent = line[: -len(line.lstrip())]
Expand Down Expand Up @@ -286,7 +287,7 @@ def write(self, *a, **kw):
cimports = cimport_statement
else:
if new_indent != indent:
if import_section:
if import_section and did_contain_imports:
import_statement = import_statement.lstrip()
else:
indent = new_indent
Expand Down
13 changes: 8 additions & 5 deletions tests/unit/test_ticketed_features.py
Expand Up @@ -876,18 +876,21 @@ 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("""
assert (
isort.code(
"""
import os
import os
""") == """
"""
)
== """
import os
"""


)

0 comments on commit 69f2a35

Please sign in to comment.