Skip to content

noqa comment is moved from long import #1456

@jtamagnan

Description

@jtamagnan

This bug reminds me a bit of #1427 and I hoped that the release of 5.5.0 would fix this as well but looking at the fix #1430, it makes sense that it wouldn't.

Given:

from my.horribly.long.import.line.that.just.keeps.on.going.and.going.and.going import (  # noqa
    my_symbol
)

isort produces:

from my.horribly.long.import.line.that.just.keeps.on.going.and.going.and.going import (
    my_symbol  # noqa
)

A simple testcase to reproduce this is with all of the settings that I have enabled is:

def test_comments_should_never_be_moved_between_imports_issue_1456():
    """isort should never move comments to a different line of the same import statement.
    See: https://github.com/PyCQA/isort/issues/1456
    """
    assert isort.check_code(
        """from my.horribly.long.import.line.that.just.keeps.on.going.and.going.and.going import (  # noqa
    my_symbol
)
        """,
        force_single_line=True,
        show_diff=True,
        multi_line_output=3,
        include_trailing_comma=True,
        force_grid_wrap=0,
        use_parentheses=True,
        line_length=79,
    )

A more minimal testcase would be:

def test_comments_should_never_be_moved_between_imports_issue_1456():
    """isort should never move comments to different import statement.
    See: https://github.com/PyCQA/isort/issues/1456
    """
    assert isort.check_code(
        """from my.horribly.long.import.line.that.just.keeps.on.going.and.going.and.going import (  # noqa
    my_symbol
)
        """,
        force_single_line=True,
        use_parentheses=True,
        multi_line_output=3,
        line_length=79,
        show_diff=True,
    )

Thank you for the steady streams of updates and fixes that you keep providing to all of your users; we owe our beautiful import statements to you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingduplicateThis issue or pull request already existsintegration

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions