No. Ruff flags unused imports (F401) and local variables (F841) one file at a time; it has no rule for functions or classes nothing calls (ruff#872, open since 2022). Add Vulture, deadcode or Skylos next to it. Ruff also reports names redefined before use (F811) and unused arguments (ARG001–ARG005), all within a single file.
The request to add this to Ruff, astral-sh/ruff#872 "Add support for vulture-like dead code detection", has been open since 22 November 2022. On 10 Oct 2026 it had 189 thumbs-up and 16 comments.
Ruff's rules for unused code
From ruff rule --all in Ruff 0.17.0:
| Rule | Name | What it reports |
|---|---|---|
| F401 | unused-import | An import the file doesn't use (safe autofix) |
| F841 | unused-variable | A local variable that is assigned and never used |
| F811 | redefined-while-unused | A name defined again before the first definition was used |
| F842 | unused-annotation | A local variable that is annotated and never used |
| RUF059 | unused-unpacked-variable | An unused name from tuple unpacking |
| B007 | unused-loop-control-variable | A loop variable the body never uses |
| ARG001–ARG005 | unused-*-argument | Unused function, method, class method, static method and lambda arguments |
| PYI018, PYI046, PYI047, PYI049 | unused-private-* | A private TypeVar, Protocol, type alias or TypedDict the file never uses |
Every one of these can be decided by reading one file. None of them answers "is this function used anywhere?"
A three-file example
# app/billing.py
import os
import json
def compute_total(items):
subtotal = sum(item["price"] for item in items)
discount = 0
return subtotal
def legacy_invoice_format(total):
return json.dumps({"total": total})
# app/main.py
from app.billing import compute_total
def run():
print(compute_total([{"price": 3}]))
if __name__ == "__main__":
run()
legacy_invoice_format is defined and never called anywhere. Ruff 0.17.0:
$ ruff check --select F --output-format concise .
app/billing.py:1:8: F401 [*] `os` imported but unused
app/billing.py:7:5: F841 Local variable `discount` is assigned to but never used
Found 2 errors.
Skylos 4.47.1 on the same project:
$ skylos . --format concise
app/billing.py:11 SKY-U001 unused function: legacy_invoice_format
app/billing.py:1 SKY-U002 unused import: os
app/billing.py:7 SKY-U003 unused variable: discount
Ruff isn't wrong here. It was never asked the question. Whether legacy_invoice_format is used depends on main.py, on tests, on anything that imports app.billing, and possibly on a framework that calls it by name. A per-file linter can't see any of that, and that design is a big part of why Ruff is so fast.
On a real-shaped app
We also ran Ruff, Vulture, deadcode and Skylos on a small Flask app with 6 hand-labelled dead items: an unused import, an unused local, two unused functions, a helper only a dead function calls, and an unused class.
| Tool | Dead items found (of 6) | Live code reported as dead |
|---|---|---|
Ruff 0.17.0, ruff check --select F,ARG . | 2 | 1 |
Vulture 2.16, vulture . | 5 | 9 |
deadcode 2.4.1, deadcode . | 5 | 8 |
Skylos 4.47.1, skylos . | 5 | 3 |
Ruff found the unused import and the unused variable. Its one false positive was ARG001 on the error argument of an @app.errorhandler function, which Flask requires. The whole-project tools found the functions and the class, and each reported some live framework code as dead; the dead code detection guide has the full output and how to configure each one.
Ruff unused functions: why there is no rule
Ruff checks each file on its own, which is why it is fast. Deciding that a function is unused needs every file at once. These cases need a whole-project scan:
- Unused functions, classes and methods across modules. The core case above.
- Transitive dead code. If function A is dead and it's the only caller of B, then B is dead too. You only see B after you account for A.
- Framework entry points. Flask and FastAPI routes, Django views listed in
urlpatterns, pytest fixtures and Celery tasks are called by the framework, not by your code. A naive whole-project scan reports them as unused. A useful one knows the conventions or lets you declare them. - Dynamic use.
getattr(obj, f"handle_{name}"), plugin registries and string-based imports. No static tool sees all of these, so every option below gives you a way to mark code as used.
Your options next to Ruff
| Vulture | deadcode | Skylos | coverage.py | |
|---|---|---|---|---|
| What it is | Dedicated dead-code finder | Dead-code finder with autofix | Dead code plus optional security, secrets and quality checks | Records which lines ran |
| Licence | MIT | AGPL-3.0 | Apache-2.0 | Apache-2.0 |
| Latest release (10 Oct 2026) | 2.16, 25 Mar 2026 | 2.4.1, 9 Aug 2024 | 4.47.1, 8 Oct 2026 | — |
| Ranking findings | Confidence by code type: 60%, 90% or 100% | None | Confidence 0–100 with evidence | n/a |
| Framework entry points | Whitelists, --ignore-decorators, --ignore-names | Ignore options | Built in for Flask, FastAPI, Django, pytest and others, plus config | Sees whatever ran |
| Fails CI on findings | Yes, exits 3 | No, exits 0 (#35) | Yes, with --strict | n/a |
| Removes code | No | --fix | skylos clean --dry-run previews; --apply writes | No |
- Vulture is the long-standing choice. It needs configuration for framework code; see Vulture false positives: tested configs.
- deadcode offers automatic removal. Its last release was August 2024, and two open issues matter: exit code 0 when issues are found, and an error on Python 3.14.
- Skylos (our tool) builds a project-wide graph, follows dead code transitively, and models common Python frameworks. It has gaps too: in 4.47.1 it doesn't recognise Flask's
@bp.before_app_requesthooks or report unused Django class-based views, and a reachablegetattr(self, f"do_{action}")can make it stop reporting unused functions altogether. - coverage.py gives evidence no static tool has: this line ran. It only knows about what you exercised, so pair it with a static scan.
For a side-by-side of the three static tools on Flask and Django apps, see deadcode vs Vulture vs Skylos.
Removing what you find
Review first, then delete. Ruff removes unused imports with ruff check --fix. For unused functions, Skylos previews removals without writing anything (paths shortened):
$ skylos clean . --dry-run
Skipping 1 unsupported dead code item (variable). Automatic edits currently
support imports and functions only.
Dry run: would remove 2 dead code items.
app/billing.py
L1 import os (100%)
L11 function legacy_invoice_format (100%)
skylos clean . --apply writes the edits; with no flag it asks about each one.
A pre-commit setup: Ruff plus Skylos
Keep Ruff for what it's good at, and add a project-wide dead-code check after it:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.17.0
hooks:
- id: ruff-check
args: [--fix]
- repo: https://github.com/duriantaco/skylos
rev: v4.47.1
hooks:
- id: skylos-scan
args: [".", "--confidence", "70", "--strict"]
Two things to know about the skylos-scan hook:
- Its default arguments only report. The hook is named "skylos (report only)" and never fails a commit as shipped. The
argsabove replace the defaults;--strictmakes the commit fail when there is any finding at or above confidence 70. - It scans the whole repository, not only the staged files, because dead code is a whole-project question. It runs when Python files are part of the commit.
To run the same check on pull requests, skylos cicd init --no-upload writes a GitHub Actions workflow that needs no Skylos account or API key.
If Skylos reports framework code that is really used, record it instead of lowering the threshold:
[tool.skylos.whitelist]
names = ["handle_*"]
The dead-code docs cover confidence levels, suppressions and entry-point config.
Related
- Python dead code detection: find and remove unused code
- deadcode vs Vulture vs Skylos: tested comparison
- Vulture false positives: tested configs for Flask, Django and pytest
- Django dead code: find unused views and helpers
- Is there a Knip for Python?
python.lintingis deprecated in VS Code: what to use now
Try it
pip install skylos
skylos .