dead simple python dead code detection
Project description
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.0
hooks:
- id: dead
how it works
- 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
byidentify
- classify test files by the
--tests
regex
- only include files matched by the
- ast parse each file
- search for definitions and references
- 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
Release history Release notifications | RSS feed
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.0.tar.gz
(6.4 kB
view details)
Built Distribution
File details
Details for the file dead-1.5.0.tar.gz
.
File metadata
- Download URL: dead-1.5.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2b3f374b35d9a859a2890902634178984f3f6cedbd3cf2994c6b734ba69f193 |
|
MD5 | e3fb035692b6a09c29ceb7ed6517206e |
|
BLAKE2b-256 | 1f60687f15608bbd880ed1519d0d871969ebd9611762df080ae7d92e974c7a31 |
File details
Details for the file dead-1.5.0-py2.py3-none-any.whl
.
File metadata
- Download URL: dead-1.5.0-py2.py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a40f38d3359cc3c817e3beacff8038c0631a32542f367bed835da9b9113b574f |
|
MD5 | a23b51b4bf31a0889e0126f7c6b0e9c5 |
|
BLAKE2b-256 | 0fdf80d2ea63c51d8d8b848a7b650eeedba6f4879c8f416bf0c7d423237d1281 |