flake8-debugger
flake8-debugger is a plugin for the flake8 code quality tool that checks for the presence of common debugger statements (like `pdb.set_trace()`, `ipdb.set_trace()`, and `breakpoint()`) in Python code. This helps prevent accidental commits of debugging code into production. The current version is 4.1.2. Releases are made periodically, typically following updates to Python versions or the flake8 ecosystem.
Warnings
- breaking Support for Python 3.6 was dropped in version 4.1.0.
- breaking Official support for Python 2.7 was dropped in version 4.0.0.
- gotcha flake8-debugger works as a plugin and does not require any explicit imports or configuration files to enable. Simply installing it makes it active when you run the `flake8` command.
- gotcha While comprehensive, flake8-debugger relies on AST parsing and might not catch highly obfuscated or dynamic debugger calls. It primarily targets common patterns like `pdb.set_trace()` or `breakpoint()`.
Install
-
pip install flake8-debugger
Quickstart
import os
def my_function():
# This line will be flagged by flake8-debugger
if os.environ.get('DEBUG_ENABLED', 'false').lower() == 'true':
import pdb; pdb.set_trace()
print("Hello, world!")
my_function()
# To run this example:
# 1. Save the code as example.py
# 2. Run 'pip install flake8 flake8-debugger'
# 3. Run 'flake8 example.py' in your terminal
# Expected output will include an error like 'example.py:6:9: D001 debugger detected'