63 points · by McAvey · 2w ago · 18 comments
None of the newer alternatives to Vulture worked out of the box on my codebases, so I decided to build one.
The first version was in Python, then I switched to Rust for speed and to reuse Ruff's parser. It checks all of CPython in under a second.
It found lots of interesting dead code in my team's codebases, and it's the first time in years we've had a Python dead code finder in our CI.
Feedback is very welcome, especially dead code it misses.
from django.conf import settings
...
if settings.DEBUG:
...
Currently unref thinks that DEBUG is not used.Similarly, the `application` variable in asgi.py (or wsgi.py) is passed as an argument to the ASGI/WSGI server executable, but that is also marked as unused.
I'll make a PR to add some basic Django support which should address both of your points.
Results are still poor, specially on the tests side. So far the main learning has been that a tidy codebase (dep graph) is essential for it to work properly.
I'm surprised I didn't find more open source tooling tackling this effectively.
Would be nice to see the definition used placed in the docs/github readme.
I've updated the README and added a FAQ section in the docs to explain this, thanks for the question!
Here's the PR - https://github.com/Apakottur/unref/pull/121
The initial version was in Python which was pretty fast as well, decided to try Rust both for speed and to reuse more constructs from ruff/ty for better compatibility with them.
Feel free to open a GitHub issue with a few of the false positives: https://github.com/Apakottur/unref/issues
Feel free to open an issue on github if you find any false positives/negatives.
The benchmark script is in the repo so you can run it yourself, the results are from my potato computer, will probably be even faster on modern PCs.
I've updated the README to be more clear about that, thanks for pointing that out!