本文へ移動
AI NEWS JOURNAL
Hacker News Show HNAI NEWS / JOURNAL

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

I wanted a good Python dead code finder that just works, with minimal config, until Ruff adds support for that (https://github.com/astral-sh/ruff/issues/872).None of the newer alternatives to Vulture worked out of the box on my codebases, so I decided to build one.The first version was in Python, then I switched to Rust for speed and to reuse Ruff's parser. It checks all of CPython in under a second.It found lots of interesting dead code in my team's codebases, and it's the first time in years we've had a Python dead code finder in our CI.Feedback is very welcome, especially dead code it misses. Comments URL: https://news.ycombinator.com/item?id=50517410 Points: 1 # Comments: 0

翻訳サービスが停止中のため原文を表示しています。

Find dead code in Python projects: the unused functions, classes, methods, variables and attributes that nothing references. Documentation: unref.readthedocs.io Unused code piles up in every codebase, faster than ever now that AI tools write much of it. Ruff does not find unused code yet, see astral-sh/ruff#872. unref fills that gap until it does: Just works: built-in rules for pytest, unittest, Pydantic, SQLAlchemy and FastAPI, so most projects need little or no configuration. Ruff-style: same conventions, options and output style, and it covers what Ruff leaves out. Fast: written in Rust on Ruff's parser, it checks all of CPython in under a second. Modern: ty-style rule codes and configuration in pyproject.toml. Quick start 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 How it works Matched by module: a function, class or variable is used only when its own module reads it, or another module reaches it through an import, module.name or __all__. Installed base classes: base classes from the project's environment are followed, so the methods a subclass overrides count as used. Ignore comments by code: # unref: ignore[...] names the rule it ignores, and a comment that ignores nothing is reported. Benchmark Checking the whole CPython codebase (v3.14.0, about 2,100 files): Measured with scripts/benchmark.py. Contributing False positives and other bugs are welcome as issues. To contribute code, see CONTRIBUTING.md.

出典

原文を読む ↗

関連テーマ

← すべてのニュースへ