Skip to content

Commit

Permalink
Fix #1381: combine_as losing non as imports, in some cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Aug 13, 2020
1 parent eaee9e6 commit 2952db4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion isort/_version.py
@@ -1 +1 @@
__version__ = "5.4.0"
__version__ = "5.4.1"
4 changes: 2 additions & 2 deletions isort/output.py
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -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 <timothy.crosley@gmail.com>"]
license = "MIT"
Expand Down
15 changes: 15 additions & 0 deletions tests/test_regressions.py
Expand Up @@ -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)

0 comments on commit 2952db4

Please sign in to comment.