What the 60% confidence value measures#
Vulture reads source files and reports definitions that no other scanned file mentions by name. Its README at v2.16 states the limit directly: "Due to Python's dynamic nature, static code analyzers like Vulture are likely to miss some dead code. Also, code that is only called implicitly may be reported as unused."
The percentage after each finding does not measure how well the tool looked. The README assigns it by the kind of definition: 100% for unused arguments and unreachable code, 90% for imports, and 60% for attributes, classes, functions, methods, properties and variables. Values below 100% "are very rough estimates (based on the type of code chunk) for how likely it is that the code is unused." Every function finding therefore arrives at 60%, whether nothing calls it or a plugin system calls it on every request.
The constructed package below shows both cases. Commands.run dispatches with getattr(self, "cmd_" + name), and pyproject.toml registers an exporter in an entry-point group:
[project.entry-points."reportkit.exporters"]
csv = "reportkit.exporters:export_csv"
# src/reportkit/commands.py
class Commands:
def run(self, name, rows):
handler = getattr(self, "cmd_" + name)
return handler(rows)
def cmd_count(self, rows):
return len(rows)
def cmd_export(self, rows):
(ep,) = entry_points(group="reportkit.exporters", name="csv")
return ep.load()(rows)
# src/reportkit/exporters.py
def export_csv(rows): ...
def export_tsv(rows): ...
With vulture 2.16 on Python 3.11, scanning the source and the tests reports four definitions and exits 3, which the README documents as "Dead code found":
$ vulture src/ tests/
src/reportkit/commands.py:9: unused method 'cmd_count' (60% confidence)
src/reportkit/commands.py:12: unused method 'cmd_export' (60% confidence)
src/reportkit/exporters.py:4: unused function 'export_csv' (60% confidence)
src/reportkit/exporters.py:8: unused function 'export_tsv' (60% confidence)
The four lines look alike, and three of them are wrong.
Find the caller that uses a string#
Dynamic dispatch leaves text behind: an attribute prefix, a dotted path in packaging metadata, a decorator that registers the function. Search for the name and for the fragments that build it, across Python files and configuration:
$ grep -rn "cmd_\|export_csv\|export_tsv" --include=*.py --include=*.toml --include=*.cfg . | grep -v "def "
./src/reportkit/commands.py:6: handler = getattr(self, "cmd_" + name)
./pyproject.toml:6:csv = "reportkit.exporters:export_csv"
The getattr prefix explains both cmd_* methods, and the entry point names export_csv. Packaging metadata is the easy one to miss, because vulture scans .py files and the reference lives in TOML. Ask the installed environment as well, since another installed distribution can register your function in the same group:
$ python -c "from importlib.metadata import entry_points; print(entry_points(group='reportkit.exporters'))"
[EntryPoint(name='csv', value='reportkit.exporters:export_csv', group='reportkit.exporters')]
A search shows that a reference exists. A trace shows that the reference runs. The standard library's trace module lists every function a run calls:
$ python -m trace --listfuncs --module reportkit.cli export | grep -E "funcname: (Commands\.|export_)"
... modulename: commands, funcname: Commands.cmd_export
... modulename: commands, funcname: Commands.run
... modulename: exporters, funcname: export_csv
python -m trace --listfuncs --module reportkit.cli count shows Commands.cmd_count the same way. Each of these three findings now has a recorded caller: a line of source or metadata and a run that reached it. A coverage report from the test suite gives the same evidence at larger scale, with the usual caveat that a line can be uncovered because no test exercised it, not because nothing calls it.
Framework registries follow the same pattern. A function decorated with @app.route or a task decorator is called by the framework, never by your code. The README describes --ignore-decorators for this case: "This is helpful for example in Flask projects, where you can use --ignore-decorators "@app.route" to ignore all function names with the @app.route decorator."
The finding that is real#
export_tsv is the disconfirming case: it looks like the CSV exporter, which is reached dynamically, but nothing reaches it. Every search for it returns only its own definition, no entry point names it, and no trace lists it. Deleting it in a copy of the tree and reinstalling leaves the tests green:
$ grep -rn "tsv" . --include=*.py --include=*.toml --include=*.cfg --include=*.txt --include=*.ini
./src/reportkit/exporters.py:8:def export_tsv(rows):
$ # delete export_tsv, then
$ pip install -e . && python -m pytest -q
2 passed in 0.02s
That combination (no string reference anywhere, no entry point in the environment, tests passing without it) is the evidence for deletion. One fact can still overturn it: if the module is part of a published library, callers outside the repository can import the function, and no search inside the repository will find them. Check whether the name is documented or exported before removing it from a package other people install.
Record the dynamic callers so the next scan stays useful#
Once a finding has a verified caller, write it down where vulture will read it. The README recommends a whitelist: "We recommend using whitelists instead of --ignore-names or --ignore-decorators whenever possible, since whitelists are automatically checked for syntactic correctness when passed to Vulture and often you can even pass them to your Python interpreter and let it check that all whitelisted code actually still exists in your project."
--make-whitelist writes one entry for every current finding, including the real one:
$ vulture --make-whitelist src/ > whitelist.py
$ cat whitelist.py
_.cmd_count # unused method (src/reportkit/commands.py:9)
_.cmd_export # unused method (src/reportkit/commands.py:12)
export_csv # unused function (src/reportkit/exporters.py:4)
export_tsv # unused function (src/reportkit/exporters.py:8)
Accepting that file unedited would have silenced export_tsv too. Remove every entry you did not verify, then scan with the whitelist:
$ vulture src/ whitelist.py
src/reportkit/exporters.py:8: unused function 'export_tsv' (60% confidence)
A pattern is coarser. vulture --ignore-names "cmd_*" src/ suppresses the getattr methods and still reports both exporters, because the pattern encodes the dispatch rule rather than a list of names. That suits a convention that will gain new members; the whitelist suits individual entry points.
Decide from the references you found#
| What vulture reports | Evidence to collect | Decision |
|---|---|---|
| Unused method with a shared prefix, 60% | A getattr, __getattr__ or dispatch table that builds the name | Keep; add an --ignore-names pattern for the prefix |
Unused function named in pyproject.toml, setup.cfg or an installed entry point | The entry-point group and a trace or test that loads it | Keep; add it to a reviewed whitelist |
| Unused function under a framework decorator | The decorator and the framework's registration | Keep; use --ignore-decorators or a whitelist entry |
| Unused function with no string reference, no entry point, not public API | Search results, the environment's entry points, tests passing after deletion | Delete it |
| Unused name in a published library | Whether docs or __all__ export it | Collect usage outside the repository before deleting |
| Unused import or argument at 90% or 100% | The line itself | Usually fix directly; the dynamic-use question rarely applies |
An automated reviewer that calls a function unused needs the same search, but its claim also has to be checked against the diff it read; the guide to validating an AI review finding covers that. When vulture runs beside a linter that already reports unused names, the guide to findings already covered by lint explains how to keep one owner for each kind of finding.