eradicate: Remove Commented-Out Code
Eradicate is a Python library and command-line tool designed to remove commented-out code from Python files. It identifies block comments that contain valid Python syntax, which are likely to be old, commented-out code, helping to clean up repositories. It aims to avoid false positives by intelligently detecting code patterns within comments. The library is actively maintained, with version 3.0.1 released recently, focusing on Python version compatibility and continuous improvements.
Warnings
- breaking Version 3.0.0 dropped support for Python 2.7, 3.6, 3.7, and 3.8. Users on these older Python versions must remain on `eradicate` < 3.0.0.
- breaking Version 2.0.0 introduced a 'New class-based API'. While `eradicate` is primarily a CLI tool, direct programmatic users relying on older internal APIs might experience breaking changes.
- gotcha Eradicate might occasionally produce false positives (removing legitimate comments) or false negatives (missing actual commented-out code).
Install
-
pip install eradicate
Imports
- eradicate
import eradicate
Quickstart
echo "# import os\na = 4\n#print('hello')" > example.py
eradicate --in-place example.py
cat example.py
# Expected output of example.py:
# a = 4
#