Skip to content

broken flake8 noqa on multi-line imports #1415

@ndevenish

Description

@ndevenish

Our code:

from dials.test.algorithms.spot_prediction.test_scan_static_reflection_predictor import ( # noqa: F401
    data as static_test,
)

And flake8 --select F401 test_noqa.py gives no error. When isort is run in --profile=black mode it moves the comment somewhere that flake8 no longer recognises:

from dials.test.algorithms.spot_prediction.test_scan_static_reflection_predictor import (
    data as static_test,  # noqa: F401
)

Now, flake8 counts this as an unused import, because flake8 only handles first-line or continuations. There was a ticket (https://gitlab.com/pycqa/flake8/-/issues/385) documenting this but this was closed as a duplicate of a ticket adding continuation handling, so this is still a problem.

This... sounds pretty similar to #1004 except there's no splitting involved. The pre-isort noqa example there doesn't seem to work in flake8 in my tests anyway, so I'm not sure if the intentions overlap.

Can be worked around with isort:skip on the noqa line.

flake8: 3.8.3 (mccabe: 0.6.1, pycodestyle: 2.6.0, pyflakes: 2.2.0) CPython 3.6.10`
isort: 5.4.2 (though running off develop because I needed the fix from 19221a3)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions