[](https://github.com/asottile/dead/actions/workflows/main.yml)
[](https://results.pre-commit.ci/latest/github/asottile/dead/main)
dead
====
dead simple python dead code detection
## installation
```bash
pip install dead
```
## cli
Consult the help for the latest usage:
```console
$ 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](https://github.com/pre-commit/pre-commit) for instructions
Sample `.pre-commit-config.yaml`:
```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`](https://github.com/chriskuehl/identify)
- classify test files by the `--tests` regex
1. ast parse each file
- search for definitions and references
1. 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._
Raw data
{
"_id": null,
"home_page": "https://github.com/asottile/dead",
"name": "dead",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Anthony Sottile",
"author_email": "asottile@umich.edu",
"download_url": "https://files.pythonhosted.org/packages/76/69/4f7962497d9a6e63337803feba4c7da24cdd80fc361ba2ae0436a150ea9f/dead-2.1.0.tar.gz",
"platform": null,
"description": "[](https://github.com/asottile/dead/actions/workflows/main.yml)\n[](https://results.pre-commit.ci/latest/github/asottile/dead/main)\n\ndead\n====\n\ndead simple python dead code detection\n\n## installation\n\n```bash\npip install dead\n```\n\n\n## cli\n\nConsult the help for the latest usage:\n\n```console\n$ dead --help\nusage: dead [-h] [--files FILES] [--exclude EXCLUDE] [--tests TESTS]\n\noptional arguments:\n -h, --help show this help message and exit\n --files FILES regex for file inclusion, default: ''\n --exclude EXCLUDE regex for file exclusion, default '^$'\n --tests TESTS regex to mark files as tests, default\n '(^|/)(tests?|testing)/'\n```\n\nrun the `dead` utility from the root of a git repository.\n\n## as a pre-commit hook\n\nSee [pre-commit](https://github.com/pre-commit/pre-commit) for instructions\n\nSample `.pre-commit-config.yaml`:\n\n```yaml\n- repo: https://github.com/asottile/dead\n rev: v2.1.0\n hooks:\n - id: dead\n```\n\n### how it works\n\n1. find all files in a repository using `git ls-files` and filtering:\n - only include files matched by the `--files` regex\n - exclude files matched by the `--exclude` regex\n - only include files identified as `python` by\n [`identify`](https://github.com/chriskuehl/identify)\n - classify test files by the `--tests` regex\n1. ast parse each file\n - search for definitions and references\n1. report things which do not have references\n\n### false positives\n\nI wrote this in ~15 minutes on an airplane, it's far from perfect but often\nfinds things. Here's a few things it's not good at:\n\n- functions which implement an interface are often marked as unused\n- metaclass magic is often marked as unused (enums, model classes, etc.)\n\n### suppressing `dead`\n\nThe `# dead: disable` comment will tell `dead` to ignore\nany line which has reportedly dead code.\n\n### is this project dead?\n\n_maybe._\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "dead simple python dead code detection",
"version": "2.1.0",
"project_urls": {
"Homepage": "https://github.com/asottile/dead"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "71a2a7b4945efa8df89f0a580b7a9dd2f06dd2ac45e6b55abbaf696577f432f9",
"md5": "fb30cd627c0464d1fa1f214c49d75bd4",
"sha256": "cde897c473a384673b4541f8d5bab4947d6240e1c195737467fe6c646585cd44"
},
"downloads": -1,
"filename": "dead-2.1.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "fb30cd627c0464d1fa1f214c49d75bd4",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.9",
"size": 6758,
"upload_time": "2025-02-08T19:58:46",
"upload_time_iso_8601": "2025-02-08T19:58:46.693223Z",
"url": "https://files.pythonhosted.org/packages/71/a2/a7b4945efa8df89f0a580b7a9dd2f06dd2ac45e6b55abbaf696577f432f9/dead-2.1.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "76694f7962497d9a6e63337803feba4c7da24cdd80fc361ba2ae0436a150ea9f",
"md5": "c0283ff26beeecac514ae3d989623c09",
"sha256": "e2b53c1ade71fc4aadafa74237b034b622d0bd3d81811d336d64e67083439d76"
},
"downloads": -1,
"filename": "dead-2.1.0.tar.gz",
"has_sig": false,
"md5_digest": "c0283ff26beeecac514ae3d989623c09",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 6516,
"upload_time": "2025-02-08T19:58:48",
"upload_time_iso_8601": "2025-02-08T19:58:48.260506Z",
"url": "https://files.pythonhosted.org/packages/76/69/4f7962497d9a6e63337803feba4c7da24cdd80fc361ba2ae0436a150ea9f/dead-2.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-08 19:58:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "asottile",
"github_project": "dead",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "dead"
}