Save progress on fixing 1321
diff --git a/isort/output.py b/isort/output.py
index 620a415..5098fd9 100644
--- a/isort/output.py
+++ b/isort/output.py
@@ -413,6 +413,7 @@
and parsed.imports[section]["from"][module][from_import]
)
):
+ #breakpoint()
from_import_section.append(from_imports.pop(0))
if star_import:
import_statement = import_start + (", ").join(from_import_section)
diff --git a/isort/parse.py b/isort/parse.py
index 283d09a..a1a70e2 100644
--- a/isort/parse.py
+++ b/isort/parse.py
@@ -322,6 +322,7 @@
nested_module = just_imports[as_index - 1]
module = just_imports[0] + "." + nested_module
as_name = just_imports[as_index + 1]
+ categorized_comments["nested"].setdefault(just_imports[0], {})[nested_module] = ", ".join(comments)
if nested_module == as_name and config.remove_redundant_aliases:
pass
elif as_name not in as_map["from"][module]:
@@ -333,9 +334,9 @@
pass
elif as_name not in as_map["straight"][module]:
as_map["straight"][module].append(as_name)
- if not config.combine_as_imports:
+
categorized_comments["straight"][module] = comments
- comments = []
+ comments = []
del just_imports[as_index : as_index + 2]
if type_of_import == "from":
import_from = just_imports.pop(0)
diff --git a/tests/test_regressions.py b/tests/test_regressions.py
index 275c8b2..721621f 100644
--- a/tests/test_regressions.py
+++ b/tests/test_regressions.py
@@ -427,3 +427,17 @@
from ast import excepthandler
"""
)
+
+
+def test_losing_comments_when_combine_as_is_set_issue_1321():
+ """Tests to ensure isort doesn't remove comments information when used in conjunction with
+ combine_as_imports.
+ See: https://github.com/timothycrosley/isort/issues/1321
+ """
+ assert isort.check_code(
+ """from foo import * # noqa
+from foo import bar as quux # noqa
+""",
+ show_diff=True,
+ combine_as_imports=True,
+ )