Vulture
Vulture is a Python library and command-line tool designed to find dead code in Python programs. It analyzes your code for unused functions, classes, methods, and variables by building an abstract syntax tree (AST) and then performing reachability analysis. Currently at version 2.16, it maintains an active development cycle with several releases per year, incorporating new Python version support and bug fixes.
Warnings
- breaking Vulture versions 2.15 and later require Python 3.9 or newer. Support for Python 3.8 was dropped.
- breaking Vulture versions 2.10 and later require Python 3.8 or newer. Support for Python 3.7 was dropped.
- breaking Vulture versions 2.9 and later require Python 3.7 or newer. Support for Python 3.6 was dropped.
- gotcha Starting from version 2.9, the `vulture` command-line tool exits with code 3 if dead code is found. Previously, it would exit with code 0 regardless of whether dead code was found, making it harder to use in CI/CD pipelines.
Install
-
pip install vulture
Imports
- Vulture
from vulture import Vulture
Quickstart
from vulture import Vulture
code_string = """
def my_unused_function():
return 42
def my_used_function():
print('Hello')
my_used_function()
"""
v = Vulture()
v.scan(code_string)
print("Found dead code:")
for item in v.get_unused_code():
print(f"- {item.typ}: {item.name} at {item.filename}:{item.lineno}")