summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2019-12-23 02:31:01 -0800
committerTimothy Crosley <timothy.crosley@gmail.com>2019-12-23 02:31:01 -0800
commit9c7668375f911b4da53f6eb1ab6287c65da7f720 (patch)
treec469ec986d0403541af2193b583ff1f446b95a43
parentce8a42f7e829109fec33239c36a31b31a961ad20 (diff)
downloadisort-9c7668375f911b4da53f6eb1ab6287c65da7f720.tar.gz
Fix section comment handling
-rw-r--r--isort/api.py5
-rw-r--r--isort/output.py5
2 files changed, 4 insertions, 6 deletions
diff --git a/isort/api.py b/isort/api.py
index f866c058..d9cfabeb 100644
--- a/isort/api.py
+++ b/isort/api.py
@@ -175,10 +175,11 @@ def sort_imports(
if not line_separator:
line_separator = line[-1]
- if index == 0 and line.startswith("#"):
+ stripped_line = line.strip()
+ if index == 0 and line.startswith("#") and stripped_line not in section_comments:
in_top_comment = True
elif in_top_comment:
- if not line.startswith("#") or line in section_comments:
+ if not line.startswith("#") or stripped_line in section_comments:
in_top_comment = False
first_comment_index_end = index - 1
elif '"' in line or "'" in line:
diff --git a/isort/output.py b/isort/output.py
index a6b4a7a9..f2d287a7 100644
--- a/isort/output.py
+++ b/isort/output.py
@@ -122,10 +122,7 @@ def sorted_imports(
section_title = config.import_headings.get(section_name.lower(), "")
if section_title:
section_comment = f"# {section_title}"
- if (
- section_comment not in parsed.lines_without_imports[0:1]
- and section_comment not in parsed.in_lines[0:1]
- ):
+ if section_comment not in parsed.lines_without_imports[0:1]:
section_output.insert(0, section_comment)
if pending_lines_before or not no_lines_before: