dead simple python dead code detection
Clone or download
Latest commit c3c450a Jan 9, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.coveragerc initial commit Jan 8, 2019
.gitignore initial commit Jan 8, 2019
.pre-commit-config.yaml Add double-quote-string-fixer to pre-commit hooks Jan 9, 2019
.travis.yml initial commit Jan 8, 2019
LICENSE initial commit Jan 8, 2019
README.md initial commit Jan 8, 2019
dead.py Add double-quote-string-fixer to pre-commit hooks Jan 9, 2019
mypy.ini initial commit Jan 8, 2019
requirements-dev.txt initial commit Jan 8, 2019
setup.cfg initial commit Jan 8, 2019
setup.py v0.0.1 Jan 9, 2019
tox.ini initial commit Jan 8, 2019

README.md

Build Status

dead

dead simple python dead code detection

installation

pip install dead

cli

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.

how it works

  1. find all files in a repository using git ls-files and filtering:
    • only include files matched by the --files regex
    • exclude files matched by the --exclude regex
    • only include files identified as python by identify
    • classify test files by the --tests regex
  2. ast parse each file
    • search for definitions and references
  3. report things which do not have references

false positives

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.)

is this project dead?

maybe.