Description
Vulture eats some Python - PyCon Italia 2022
Maintaining a high level of code quality is important for any serious project. One aspect of this is ensuring that all code is actually used. Finding and removing dead code allows to keep the code base clean and reduces bugs. This is a practical guide on using and configuring Vulture to do so. This talk is focused on how we can use Vulture to find dead code. There are many reasons for dead code ending up in a project. The most common is refactoring, but another is misspellings, which are only detected at runtime for dynamic languages. Vulture helps you find unused code in Python programs, and it is useful for cleaning up and finding errors in large codebases. If you run Vulture on both your library and test suite, you can find untested code.
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 (e.g., using getattr) may be reported as unused. Nonetheless, Vulture can be a very helpful tool for higher code quality.
The second part of this talk investigates ways to improve Vulture’s reporting such that the results are actionable and optimized for a low number of false positives. It also discusses how to automate testing for dead code with Vulture – there are quite a few options available: 1. Add a step in your continuous integration testing. 2. As a pre-commit hook. 3. Run a script using Vulture API for more fine-grained control.
The third and last part of this talk discusses a brief overview of the internal workings of the tool, along with the scope of future improvements. After all, the motive of this talk is not only to encourage developers to prioritize code hygiene but also to inspire them to come up with ideas to enable it.
Speaker: Rahul Jha