Skip to content

Commit

Permalink
Fixes #1838: don't append imports where no imports are present
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Nov 3, 2021
1 parent 223dc4c commit 73245e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion isort/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def process(
next_import_section = ""

if import_section:
if add_imports and not indent:
if add_imports and (contains_imports or not config.append_only) and not indent:
import_section = (
line_separator.join(add_imports) + line_separator + import_section
)
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_ticketed_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,19 @@ def test_isort_supports_append_only_imports_issue_727():
"""
)

# issue 1838: don't append in middle of class
assert isort.check_code(
'''class C:
"""a
"""
# comment
''',
append_only=True,
add_imports=["from __future__ import annotations"],
show_diff=True,
)


def test_isort_supports_shared_profiles_issue_970():
"""Test to ensure isort provides a way to use shared profiles.
Expand Down

0 comments on commit 73245e9

Please sign in to comment.