build status pre-commit.ci status
dead simple python dead code detection
pip install dead
Consult the help for the latest usage:
$ dead --help usage: dead [-h] [--files FILES] [--exclude EXCLUDE] [--tests TESTS] optional arguments: -h, --help show this help message and exit --files FILES regex for file inclusion, default: '' --exclude EXCLUDE regex for file exclusion, default '^$' --tests TESTS regex to mark files as tests, default '(^|/)(tests?|testing)/'
run the dead utility from the root of a git repository.
See pre-commit for instructions
Sample .pre-commit-config.yaml:
- repo: https://github.com/asottile/dead rev: v2.1.0 hooks: - id: dead
- find all files in a repository using
git ls-filesand filtering:- only include files matched by the
--filesregex - exclude files matched by the
--excluderegex - only include files identified as
pythonbyidentify - classify test files by the
--testsregex
- only include files matched by the
- ast parse each file
- search for definitions and references
- report things which do not have references
I wrote this in ~15 minutes on an airplane, it's far from perfect but often finds things. Here's a few things it's not good at:
- functions which implement an interface are often marked as unused
- metaclass magic is often marked as unused (enums, model classes, etc.)
The # dead: disable comment will tell dead to ignore
any line which has reportedly dead code.
maybe.