summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2020-08-28 03:04:20 -0700
committerTimothy Crosley <timothy.crosley@gmail.com>2020-08-28 03:04:20 -0700
commit104ed84c66bb4138c0131adb5176ccb79f7812db (patch)
tree04c2d059e9d49e591fdb3a9f0617a445853a552b
parent050d6b547cf41a86149d7aa4820469b060012d39 (diff)
downloadisort-issue/1420/fix-isort-unclean-check-on-add-depending-on-doc-string-position.tar.gz
Fix #1420: Ensure isort doesn't include new imports in comparisonissue/1420/fix-isort-unclean-check-on-add-depending-on-doc-string-position
-rw-r--r--isort/core.py2
-rw-r--r--tests/unit/test_regressions.py15
2 files changed, 15 insertions, 2 deletions
diff --git a/isort/core.py b/isort/core.py
index 35738abd..908be4e1 100644
--- a/isort/core.py
+++ b/isort/core.py
@@ -215,9 +215,7 @@ def process(
if not import_section:
output_stream.write(line)
line = ""
- import_section += line_separator.join(add_imports) + line_separator
contains_imports = True
- add_imports = []
else:
not_imports = True
elif (
diff --git a/tests/unit/test_regressions.py b/tests/unit/test_regressions.py
index 98621545..eb10dc81 100644
--- a/tests/unit/test_regressions.py
+++ b/tests/unit/test_regressions.py
@@ -617,3 +617,18 @@ from ..fileB import b_var
lines_after_imports=2,
no_lines_before="LOCALFOLDER",
)
+
+
+def test_isort_should_be_able_to_add_independent_of_doc_string_placement_issue_1420():
+ """isort should be able to know when an import requested to be added is sucesfully added,
+ independent of where the top doc string is located.
+ See: https://github.com/PyCQA/isort/issues/1420
+ """
+ assert isort.check_code(
+ '''"""module docstring"""
+
+import os
+''',
+ show_diff=True,
+ add_imports=["os"],
+ )