Distinguish same-named functions across modules - #417
Open
ethanleifer wants to merge 5 commits into
Open
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #417 +/- ##
==========================================
+ Coverage 93.46% 93.77% +0.31%
==========================================
Files 9 9
Lines 597 675 +78
==========================================
+ Hits 558 633 +75
- Misses 39 42 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Intern <intern@agency.inc>
ethanleifer
marked this pull request as ready for review
May 18, 2026 16:14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This changes function tracking so functions with the same local name in different modules are treated as distinct definitions when Vulture can derive a module from the scanned filename.
Today, Vulture stores function definitions by bare name only. That means a use of
load_configin one module can mark everyload_configdefinition in the scanned project as used, including definitions in unrelated modules. This creates false negatives for projects that commonly reuse conventional function names across modules.Motivation
For example, with two modules that each define a
load_configfunction, calling one of them should not suppress the unused report for the other:After this change, Vulture reports
package.reports.loaders.load_configas unused while recognizingpackage.commands.loaders.load_configas used.Approach
.pyfilenames, including__init__.pyhandling.Item.nameas the local identifier, e.g.load_config.Item.module, e.g.package.commands.loaders.Item.full_namefor function matching/reporting, e.g.package.commands.loaders.load_config.used_namesset for current behavior and public test expectations.Compatibility notes
This changes report and whitelist output for unused functions when Vulture is given filenames that can be converted to module names. For example,
foo.pynow reportsfoo.myfuncinstead ofmyfunc.I kept the change scoped to functions to address the cross-module false-negative case without attempting full scope-aware analysis. Methods with the same name on different classes are still intentionally outside the scope of this PR.
Related issues
This is related to the broader set of false negatives caused by name-only matching, including:
Tests
python -m ruff format tests/test_item.py tests/test_scavenging.pypython -m ruff check vulture/core.py tests/test_item.py tests/test_scavenging.py tests/test_report.pypython -m pytest tests/test_item.py tests/test_scavenging.py tests/test_report.pypython -m pytestpython -m coverage report -m vulture/core.py