Skip to main content

dead simple python dead code detection

Project description

build status pre-commit.ci 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.

as a pre-commit hook

See pre-commit for instructions

Sample .pre-commit-config.yaml:

-   repo: https://github.com/asottile/dead
    rev: v1.5.2
    hooks:
    -   id: dead

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

suppressing dead

The # dead: disable comment will tell dead to ignore any line which has reportedly dead code.

is this project dead?

maybe.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dead-1.5.2.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

dead-1.5.2-py2.py3-none-any.whl (6.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file dead-1.5.2.tar.gz.

File metadata

  • Download URL: dead-1.5.2.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for dead-1.5.2.tar.gz
Algorithm Hash digest
SHA256 06d82da0adcac7821d45b147c019b3852644f9a23493c0b1578f1c8a7e4e73fd
MD5 449076ffc0c4363aca99973ee067b631
BLAKE2b-256 1ac3be1b53fff92d02c8f51dc4c18a49f40f982e5736f3d835ba5e79caccfaad

See more details on using hashes here.

File details

Details for the file dead-1.5.2-py2.py3-none-any.whl.

File metadata

  • Download URL: dead-1.5.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for dead-1.5.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4e97c2e4f4c4751b908b56831ab52a34d247570f6ef650c8a34b8b51950540bb
MD5 eb995c660cf0ba358e3fcfafe6034e02
BLAKE2b-256 fe5f964ca37c7b04c32b72885bd00cabeb6dc6165e4218eabc24f3c8b89c5a27

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page