Show HN: Unref – A Python dead code finder built on Ruff's parser
Hacker News

Show HN: Unref - A Python dead code finder built on Ruff's parser

An extremely fast Python dead code finder, written in Rust. Checking the whole CPython codebase (v3.15.0, about 2,300 files), measured with scripts/benchmark.py.

Features

  • Fast: 20x faster than vulture, it checks all of CPython in under a second.
  • Just works: built-in rules for pytest, Pydantic, SQLAlchemy and more, so most projects need little or no configuration.
  • Accurate: names are matched by module, so a used parse in one module does not hide an unused parse in another.
  • Ruff-style: same conventions, options and output style as Ruff, and it finds the unused code Ruff leaves out.
  • Modern: ty-style rule codes, configuration in pyproject.toml, built on Ruff's parser.
  • Fits your workflow: runs with uvx, as a pre-commit or prek hook, and in GitHub Actions.

Documentation: unref.readthedocs.io

Usage

Run it with uvx:

$ uvx unref
src/project/models.py:12:7: unused-class 'Account'
src/project/utils.py:40:5: unused-function 'parse_date'

Or as a pre-commit or prek hook, alongside Ruff:

repos:
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.17.4
    hooks:
      - id: ruff-check
      - id: ruff-format
  - repo: https://github.com/Apakottur/unref
    rev: v0.2.0 # Or run `pre-commit autoupdate`.
    hooks:
      - id: unref

Contributing

False positives and other bugs are welcome as issues. To contribute code, see CONTRIBUTING.md.

Read on Hacker News ↗ ← Back to News

Comments

No comments yet. Start the discussion.