File tree 2 files changed +14
-1
lines changed
2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -355,7 +355,7 @@ def process(
355
355
next_import_section = ""
356
356
357
357
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 :
359
359
import_section = (
360
360
line_separator .join (add_imports ) + line_separator + import_section
361
361
)
Original file line number Diff line number Diff line change @@ -213,6 +213,19 @@ def test_isort_supports_append_only_imports_issue_727():
213
213
"""
214
214
)
215
215
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
+
216
229
217
230
def test_isort_supports_shared_profiles_issue_970 ():
218
231
"""Test to ensure isort provides a way to use shared profiles.
You can’t perform that action at this time.
0 commit comments