File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -454,6 +454,17 @@ def _with_from_imports(
454454 parsed .categorized_comments ["nested" ].get (module , {}).pop (from_import , None )
455455 )
456456 if comment :
457+ # If the comment is a noqa and hanging indent wrapping is used,
458+ # keep the name in the main list and hoist the comment to the statement.
459+ if (
460+ comment .lower ().startswith ("noqa" )
461+ and config .multi_line_output
462+ == wrap .Modes .HANGING_INDENT # type: ignore[attr-defined]
463+ ):
464+ comments = list (comments ) if comments else []
465+ comments .append (comment )
466+ continue
467+
457468 from_imports .remove (from_import )
458469 if from_imports :
459470 use_comments = []
Original file line number Diff line number Diff line change @@ -5741,3 +5741,16 @@ def test_reexport_multiline_long_rollback() -> None:
57415741test
57425742"""
57435743 assert isort .code (test_input , config = Config (sort_reexports = True )) == expd_output
5744+
5745+
5746+ def test_noqa_multiline_hanging_indent () -> None :
5747+ test_input = (
5748+ "from aaaaaaa import bbbbbbbbbbbbbbbbb, ccccccccccccccccccc, dddddddddddddddd"
5749+ "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee, \\ \n "
5750+ " fffffffffffffffffffff # noqa: E402\n "
5751+ "\n "
5752+ "print(fffffffffffffffffffff)\n "
5753+ "print(dddddddddddddddd)\n "
5754+ )
5755+ output = isort .code (test_input , line_length = 120 , multi_line_output = WrapModes .HANGING_INDENT )
5756+ assert output == test_input
You can’t perform that action at this time.
0 commit comments