diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f2c86b85..7fd5957fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ Changelog 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 fc30498fa..1e41bf8f7 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 086ece72f..6a21c1315 100644 --- a/isort/output.py +++ b/isort/output.py @@ -432,8 +432,8 @@ def _with_from_imports( ): 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 2359eed8e..bc6f2a7c4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ line-length = 100 [tool.poetry] name = "isort" -version = "5.4.0" +version = "5.4.1" description = "A Python utility / library to sort Python imports." authors = ["Timothy Crosley "] license = "MIT" diff --git a/tests/test_regressions.py b/tests/test_regressions.py index 8236329ba..6fae92d2b 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -520,3 +520,18 @@ def test_combine_as_does_not_lose_comments_issue_1321(): """ 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)