summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2020-01-13 22:50:12 -0800
committerTimothy Crosley <timothy.crosley@gmail.com>2020-01-13 22:50:12 -0800
commit2a5d7ec54a07595ded44aad3e7c5c70accdd0655 (patch)
tree07e7f212730233b686a12b96f2203aa03d273ee6
parentbe0ae7b5c7d92e019ab514880f26a7a88fe7eb65 (diff)
downloadisort-feature/fix-issue-1091.tar.gz
Fix above comments for from importsfeature/fix-issue-1091
-rw-r--r--isort/output.py19
1 files changed, 6 insertions, 13 deletions
diff --git a/isort/output.py b/isort/output.py
index 4343f71a..f7a4b2f7 100644
--- a/isort/output.py
+++ b/isort/output.py
@@ -333,18 +333,18 @@ def _with_from_imports(
)
comments = None
else:
+ above_comments = parsed.categorized_comments["above"]["from"].pop(module, None)
+ if above_comments:
+ if new_section_output and config.ensure_newline_before_comments:
+ new_section_output.append("")
+ new_section_output.extend(above_comments)
+
while from_imports and from_imports[0] in as_imports:
from_import = from_imports.pop(0)
as_imports[from_import] = sorting.naturally(as_imports[from_import])
from_comments = parsed.categorized_comments["straight"].get(
f"{module}.{from_import}"
)
- above_comments = parsed.categorized_comments["above"]["from"].pop(module, None)
- if above_comments:
- if new_section_output and config.ensure_newline_before_comments:
- new_section_output.append("")
- new_section_output.extend(above_comments)
-
if (
config.keep_direct_and_as_imports
and parsed.imports[section]["from"][module][from_import]
@@ -399,13 +399,6 @@ def _with_from_imports(
single_import_line += (
f"{comments and ';' or config.comment_prefix} " f"{comment}"
)
- above_comments = parsed.categorized_comments["above"]["from"].pop(
- module, None
- )
- if above_comments:
- if new_section_output and config.ensure_newline_before_comments:
- new_section_output.append("")
- new_section_output.extend(above_comments)
new_section_output.append(
wrap.line(single_import_line, parsed.line_separator, config)
)