Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AlexWaygood opened this issue Jul 11, 2023 · 0 comments
Labels

Comments

@AlexWaygood
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant