F401 unused import false negative
- Dominant language
- Rust
- Stars
- 49.6k
- Forks
- 2.4k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 435
Description
False negative
```
import importlib # this package is unused, but not detected
import importlib.util
package = "ruff"
is_present = importlib.util.find_spec(package)
```
When `from importlib import util` is used, correct behaviour is observed
```
import importlib # this package is unused, and detected
from importlib import util
package = "ruff"
is_present = util.find_spec(package)
```
Ruff 'v0.0.270'
(hope I'm overlooking some submodule complexity in the general case, but it seems that in this specific case `import importlib` can be safely removed)
Contributor guide
Research direction
Start with the two Python reproductions in the issue and compare their F401 results under Ruff. Trace the import-analysis entry point for F401 and add or update coverage for the importlib/importlib.util case; done means the unused importlib is detected without changing the correct from-import behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100