Skip to main content

dead simple python dead code detection

Project description

Build Status Azure DevOps coverage

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.1.0
    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.1.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

dead-1.1.0-py2.py3-none-any.whl (6.4 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: dead-1.1.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9

File hashes

Hashes for dead-1.1.0.tar.gz
Algorithm Hash digest
SHA256 0cbdaaaa869afed5233ec3513641931d3310026795a4d8c3b3352c9bfac8197a
MD5 e8cbbeec9123fd1f06fb34038d4537a9
BLAKE2b-256 46e9613e6f4367e2ca7fdeac3a47d4111da92d86edf8d81f6bf9005427ac5bc6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dead-1.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9

File hashes

Hashes for dead-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 365ee5e645b66776e185bd5be5a89a1ac5b54698733ee182cb5c65f93b58cf42
MD5 98d3f8c27f06ee4c8b3a046f9df7081f
BLAKE2b-256 fee939af0a903be0041582dce230e707061b113cfbe07b7307b03c2472239e5c

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