Fix #1381: combine_as losing non as imports, in some cases.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1f2c86b..7fd5957 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,9 @@
NOTE: isort follows the [semver](https://semver.org/) versioning standard.
+### 5.4.1 [Hotfix] Aug 13, 2020
+ - Fixed #1381: --combine-as loses # noqa in different circumstances.
+
### 5.4.0 Aug 12, 2020
- Implemented #1373: support for length sort only of direct (AKA straight) imports.
- Fixed #1380: --combine-as loses # noqa.
diff --git a/isort/_version.py b/isort/_version.py
index fc30498..1e41bf8 100644
--- a/isort/_version.py
+++ b/isort/_version.py
@@ -1 +1 @@
-__version__ = "5.4.0"
+__version__ = "5.4.1"
diff --git a/isort/output.py b/isort/output.py
index 086ece7..6a21c13 100644
--- a/isort/output.py
+++ b/isort/output.py
@@ -432,8 +432,8 @@
):
from_import_section.append(from_imports.pop(0))
if config.combine_as_imports:
- comments = parsed.categorized_comments["from"].pop(
- f"{module}.__combined_as__", ()
+ comments = (comments or []) + list(
+ parsed.categorized_comments["from"].pop(f"{module}.__combined_as__", ())
)
import_statement = with_comments(
comments,
diff --git a/pyproject.toml b/pyproject.toml
index 2359eed..bc6f2a7 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -3,7 +3,7 @@
[tool.poetry]
name = "isort"
-version = "5.4.0"
+version = "5.4.1"
description = "A Python utility / library to sort Python imports."
authors = ["Timothy Crosley <timothy.crosley@gmail.com>"]
license = "MIT"
diff --git a/tests/test_regressions.py b/tests/test_regressions.py
index 8236329..6fae92d 100644
--- a/tests/test_regressions.py
+++ b/tests/test_regressions.py
@@ -520,3 +520,18 @@
"""
assert isort.code(test_input, combine_as_imports=True) == expected_output
+
+
+def test_combine_as_does_not_lose_comments_issue_1381():
+ """Test to ensure isort doesn't lose comments when --combine-as is used.
+ See: https://github.com/timothycrosley/isort/issues/1381
+ """
+ test_input = """
+from smtplib import SMTPConnectError, SMTPNotSupportedError # important comment
+"""
+ assert "# important comment" in isort.code(test_input, combine_as_imports=True)
+
+ test_input = """
+from appsettings import AppSettings, ObjectSetting, StringSetting # type: ignore
+"""
+ assert "# type: ignore" in isort.code(test_input, combine_as_imports=True)