Skip to content

Commit

Permalink
Fixed #1744: repeat noqa comments dropped when * import and non * imp…
Browse files Browse the repository at this point in the history
…orts exist from the same package.
  • Loading branch information
timothycrosley committed Jun 13, 2021
1 parent dffefe4 commit d2f7a9f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -8,7 +8,8 @@ Find out more about isort's release policy [here](https://pycqa.github.io/isort/
- Fixed (https://github.com/PyCQA/isort/pull/1695): added imports being added to doc string in some cases.
- Fixed (https://github.com/PyCQA/isort/pull/1714): in rare cases line continuation combined with tabs can output invalid code.
- Fixed (https://github.com/PyCQA/isort/pull/1726): isort ignores reverse_sort when force_sort_within_sections is true.
- Fixed (https://github.com/PyCQA/isort/issues/1741): comments in hanging indent modes can lead to invalid code.
- Fixed #1741: comments in hanging indent modes can lead to invalid code.
- Fixed #1744: repeat noqa comments dropped when * import and non * imports exist from the same package.
- Implemented #1697: Provisional support for PEP 582: skip `__pypackages__` directories by default.
- Implemented #1705: More intuitive handling of isort:skip_file comments on streams.

Expand Down
3 changes: 1 addition & 2 deletions isort/output.py
Expand Up @@ -416,14 +416,13 @@ def _with_from_imports(
if "*" in from_imports:
output.append(
with_comments(
_with_star_comments(parsed, module, list(comments or ())),
_with_star_comments(parsed, module, []),
f"{import_start}*",
removed=config.ignore_comments,
comment_prefix=config.comment_prefix,
)
)
from_imports.remove("*")
comments = None

for from_import in copy.copy(from_imports):
comment = (
Expand Down
55 changes: 55 additions & 0 deletions tests/unit/test_regressions.py
Expand Up @@ -1725,3 +1725,58 @@ def test_isort_should_never_quietly_remove_imports_in_any_hangin_mode_issue_1741
assert "qwerty" in sorted_code
assert "efg" in sorted_code
assert "xyz" in sorted_code


def test_isort_should_keep_multi_noqa_with_star_issue_1744():
assert isort.check_code(
"""
from typing import * # noqa
from typing import IO, BinaryIO, Union # noqa
""",
show_diff=True,
)
assert isort.check_code(
"""
from typing import * # noqa 1
from typing import IO, BinaryIO, Union # noqa 2
""",
show_diff=True,
)
assert isort.check_code(
"""
from typing import * # noqa
from typing import IO, BinaryIO, Union
""",
show_diff=True,
)
assert isort.check_code(
"""
from typing import *
from typing import IO, BinaryIO, Union # noqa
""",
show_diff=True,
)
assert (
isort.code(
"""
from typing import * # hi
from typing import IO, BinaryIO, Union # noqa
""",
combine_star=True,
)
== """
from typing import * # noqa; hi
"""
)
assert (
isort.code(
"""
from typing import * # noqa
from typing import IO, BinaryIO, Union # noqa
""",
combine_star=True,
)
== """
from typing import * # noqa
"""
)

0 comments on commit d2f7a9f

Please sign in to comment.