Skip to content

Commit 73245e9

Browse files
committedNov 3, 2021
Fixes #1838: don't append imports where no imports are present
1 parent 223dc4c commit 73245e9

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed
 

‎isort/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def process(
355355
next_import_section = ""
356356

357357
if import_section:
358-
if add_imports and not indent:
358+
if add_imports and (contains_imports or not config.append_only) and not indent:
359359
import_section = (
360360
line_separator.join(add_imports) + line_separator + import_section
361361
)

‎tests/unit/test_ticketed_features.py

+13
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,19 @@ def test_isort_supports_append_only_imports_issue_727():
213213
"""
214214
)
215215

216+
# issue 1838: don't append in middle of class
217+
assert isort.check_code(
218+
'''class C:
219+
"""a
220+
221+
"""
222+
# comment
223+
''',
224+
append_only=True,
225+
add_imports=["from __future__ import annotations"],
226+
show_diff=True,
227+
)
228+
216229

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

0 commit comments

Comments
 (0)
Please sign in to comment.