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

Implement import tracking #357

Open
FozzieHi opened this issue Feb 15, 2023 · 4 comments
Open

Implement import tracking #357

FozzieHi opened this issue Feb 15, 2023 · 4 comments

Comments

@FozzieHi
Copy link
Contributor

FozzieHi commented Feb 15, 2023

I think false positives like those reported in #356 (and probably some false negatives as well) are prevalent across multiple lints and one way to solve them would be to use some form of import tracking.

I've come up with some examples below, but this is just a very rough draft.

from itertools import groupby

imported_modules = {
    "itertools": {
        "name": "itertools",
        "imports": {
            "groupby": "groupby"
        }
    }
}

from itertools import groupby as groupby_as

imported_modules = {
    "itertools": {
        "name": "itertools",
        "imports": {
            "groupby": "groupby_as"
        }
    }
}

import itertools

imported_modules = {
    "itertools": {
        "name": "itertools"
    }
}

import itertools as itertools_as

imported_modules = {
    "itertools": {
        "name": "itertools"
    }
}

Then in the lint to get the itertools id you'd use imported_modules["itertools"]["name"], and to get the groupby id you'd use imported_modules["itertools"]["imports"]["groupby"].

Is this something that we would be interested in adding?

@FozzieHi
Copy link
Contributor Author

@cooperlees What do you think about this?

@cooperlees
Copy link
Collaborator

So, just so I understand, you just want to make a generic API to add import tracking to multiple checks in a central place? Any other main goals I missed here?

@FozzieHi
Copy link
Contributor Author

Yup, just want to effectively create a method to get the import alias for a certain module, which we can then use in the checks.

@cooperlees
Copy link
Collaborator

Sounds worth adding to me, especially if we're already using it in multiple places (I forget).

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

No branches or pull requests

2 participants