Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions isort/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,17 @@ def _with_from_imports(
parsed.categorized_comments["nested"].get(module, {}).pop(from_import, None)
)
if comment:
# If the comment is a noqa and hanging indent wrapping is used,
# keep the name in the main list and hoist the comment to the statement.
if (
comment.lower().startswith("noqa")
and config.multi_line_output
== wrap.Modes.HANGING_INDENT # type: ignore[attr-defined]
):
comments = list(comments) if comments else []
comments.append(comment)
continue

from_imports.remove(from_import)
if from_imports:
use_comments = []
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_isort.py
Original file line number Diff line number Diff line change
Expand Up @@ -5741,3 +5741,16 @@ def test_reexport_multiline_long_rollback() -> None:
test
"""
assert isort.code(test_input, config=Config(sort_reexports=True)) == expd_output


def test_noqa_multiline_hanging_indent() -> None:
test_input = (
"from aaaaaaa import bbbbbbbbbbbbbbbbb, ccccccccccccccccccc, dddddddddddddddd"
"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee, \\\n"
" fffffffffffffffffffff # noqa: E402\n"
"\n"
"print(fffffffffffffffffffff)\n"
"print(dddddddddddddddd)\n"
)
output = isort.code(test_input, line_length=120, multi_line_output=WrapModes.HANGING_INDENT)
assert output == test_input
Loading