Skip to main content

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: v2.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.

Metadata

Release files for dead 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dead 2.1.0
File Size Uploaded
dead-2.1.0.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dead 2.1.0
File Interpreter ABI Platform
dead-2.1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 13.3 kB

Release files / dead-2.1.0.tar.gz

Download URL dead-2.1.0.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e2b53c1ade71fc4aadafa74237b034b622d0bd3d81811d336d64e67083439d76
BLAKE2b-256 checksum
How to use checksums
76694f7962497d9a6e63337803feba4c7da24cdd80fc361ba2ae0436a150ea9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release files / dead-2.1.0-py2.py3-none-any.whl

Download URL dead-2.1.0-py2.py3-none-any.whl
Size 6.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
cde897c473a384673b4541f8d5bab4947d6240e1c195737467fe6c646585cd44
BLAKE2b-256 checksum
How to use checksums
71a2a7b4945efa8df89f0a580b7a9dd2f06dd2ac45e6b55abbaf696577f432f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page