eradicate is a command-line utility that identifies and removes code left in source files as comments. Such fragments often remain after testing alternative implementations or temporarily disabling statements. Although they do not execute, they can obscure the current logic and make source files harder to maintain.
Rather than deleting every comment, eradicate looks for text resembling executable statements and applies checks intended to distinguish redundant code from genuine explanations. This makes it useful when cleaning an established codebase whose version control history already preserves earlier implementations. Since legitimate comments can sometimes resemble code, proposed removals should be reviewed before files are rewritten.
This is free and open source software.
Key Features
- Uses tokenization to locate comments without confusing them with hash characters inside strings.
- Checks suspected commented-out code for syntax and indicators of executable statements.
- Recognizes commented assignments, imports, function calls, and control-flow statements.
- Detects some multiline code fragments, including continued statements and bracketed expressions.
- Displays a unified diff of proposed changes without modifying the original files.
- Supports in-place editing to remove detected code directly from source files.
- Recursively scans directories for Python files, excluding hidden directories and files.
- Offers an aggressive detection mode, which may identify additional code at the risk of false positives.
- Preserves common development directives, including noqa, pylint, mypy, isort, and formatting annotations.
- Allows custom regular expression whitelists to replace or extend the default exclusions.
- Protects inline script metadata blocks and source encoding declarations.
- Preserves detected file encodings and existing line endings.
- Provides an optional nonzero exit status when changes are detected, useful for automated checks.
- Cross-platform support – runs on Linux and Windows.
Website: github.com/PyCQA/eradicate
Support:
Developer: Steven Myint
License: MIT License

eradicate is written in Python. Learn Python with our recommended free books and free tutorials.
Related Software
| Python Code Formatters | |
|---|---|
| Ruff | Extremely fast Python linter and code formatter |
| YAPF | Python formatter based on clang-format |
| Black | Uncompromising Python code formatter |
| isort | Python utility and library to sort imports |
| autopep8 | Formats Python code to conform to the PEP 8 style guide |
| Darker | Apply black reformatting to Python files |
| Pyink | Python code formatter |
| docformatter | Automatically formats Python docstrings for consistent style |
| SSort | Sorts Python statements by dependency for clearer code |
| reorder-python-imports | Reorders Python imports into a consistent, readable layout |
| μsort | Sorts import statements |
| eradicate | Remove commented-out code from Python files |
Read our verdict in the software roundup.
LinuxLinks helps you discover the best free and open source software for Linux. Explore our extensive collection of recommended applications, including alternatives to popular proprietary software.We also publish software reviews, Linux tutorials, hardware reviews, free programming books and articles covering the wider open source community. Browse our Linux resources to discover more. Know a useful free and open source Linux application we haven't covered? Suggest a program for inclusion. Has your software been featured on LinuxLinks? Display one of our Featured on LinuxLinks badges on your website or GitHub README. |


Please read our Comment Policy before commenting.