Skip to content

Commit

Permalink
Fixed #1297: Usage of alongside is broken.
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Jul 8, 2020
1 parent a35e464 commit 9ce5f74
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ NOTE: isort follows the [semver](https://semver.org/) versioning standard.
- Fixed #1275 & #1283: Blank line after docstring removed.
- Fixed #1298: CLI Help out of date with isort 5.
- Fixed #1290: Unecessary blank lines above nested imports when import comments turned on.
- Fixed #1297: Usage of `--add-imports` alongside `--check` is broken.

### 5.0.4 July 6, 2020
- Fixed #1264: a regression with comment handling and `force_sort_within_sections` config option
Expand Down
6 changes: 4 additions & 2 deletions isort/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ def _sort_imports(
not_imports = True

if not_imports:
raw_import_section: str = import_section
if (
add_imports
and not in_top_comment
Expand All @@ -521,7 +522,7 @@ def _sort_imports(
add_imports = []

if next_import_section and not import_section: # pragma: no cover
import_section = next_import_section
raw_import_section = import_section = next_import_section
next_import_section = ""

if import_section:
Expand All @@ -532,6 +533,7 @@ def _sort_imports(

if not indent:
import_section += line
raw_import_section += line
if not contains_imports:
output_stream.write(import_section)
else:
Expand All @@ -541,9 +543,9 @@ def _sort_imports(
line_separator
).startswith(COMMENT_INDICATORS):
import_section = import_section.lstrip(line_separator)
raw_import_section = raw_import_section.lstrip(line_separator)
first_import_section = False

raw_import_section: str = import_section
if indent:
import_section = line_separator.join(
line.lstrip() for line in import_section.split(line_separator)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,14 @@ def func():
)
== test_input
)


def test_add_imports_shouldnt_make_isort_unusable_issue_1297():
"""Test to ensure add imports doesn't cause any unexpected behaviour when combined with check"""
assert isort.check_code(
"""from __future__ import unicode_literals
from os import path
""",
add_imports={"from __future__ import unicode_literals"},
)

0 comments on commit 9ce5f74

Please sign in to comment.