flake8-pyi icon indicating copy to clipboard operation
flake8-pyi copied to clipboard

Flag forbidden imports on the line they occur (after dropping support for Python 3.9)

Open AlexWaygood opened this issue 2 years ago • 0 comments

Currently we have this behaviour:

from collections.abc import (  # Y057 flagged on this line for the forbidden ByteString import
    AsyncIterator,
    Awaitable,
    ByteString,
    Collection,
    Container,
    MutableMapping,
    MutableSequence,
)

It would be nice if we could have this behaviour instead, where import-related errors were flagged on the line where the import actually occurs when it's part of a multiline import statement:

from collections.abc import (
    AsyncIterator,
    Awaitable,
    ByteString,  # Y057 flagged on this line for the forbidden ByteString import
    Collection,
    Container,
    MutableMapping,
    MutableSequence,
)

As discussed in #411, however, this is pretty hard to do on Python <3.10 due to the fact that ast.alias nodes only have lineno and col_offset attributes on 3.10+. And while we still support Python <3.10, it's good to consistently flag errors on the same line regardless of the Python version being used. So this can't be addressed for now.

Once we drop support for Python 3.9, however, we should change our behaviour to use the more precise line numbers from the ast.alias nodes.

AlexWaygood avatar Jul 11 '23 17:07 AlexWaygood