PyCQA / PyCQA/flake8-bugbear

Implement import tracking

Open
#357 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.1k
Forks
123
Avg merge
2d 5h
Merged PRs (30d)
5

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the false-positive and false-negative examples in this issue and the related report in #356. Determine which lints need import information and agree on the tracking representation and integration scope; done means the proposal is specific enough to implement and its behavior is covered by examples or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.