4 ms·
Vulture: Find Dead Python Code
- wcdolphin 5y agoThis tool seems interesting, but I haven’t yet figured out how to configure it to work with Django’s dynamic nature. If anyone has had good success I’d love to hear more!
- exciteabletom 5y agoVulture has to also inspect the template files for this to work, which is probably out of the scope of the project.
- long11l 5y agoPycharm handles django projects pretty well "find usages" is a somewhat reverse way of doing it though
- DonHopkins 5y agoVultures are attracted to code smell. https://en.wikipedia.org/wiki/Code_smell https://en.wikipedia.org/wiki/Code_smell
- quicklime 5y agoI wish that code smells were a sign that this is about to become dead, but where I work that’s not the case :(
- kkirsche 5y agoWhen it works, it’s a fantastic tool. I like pairing it with codespell, interrogate, bandit, and a few other tools to get a broad idea of how my codebase is doing on different fronts. With that said, lately I’ve had issues using vulture on larger projects with various errors, so hopefully they’ll continue to develop it and address those.
- bottled_poe 5y agoI feel unit test coverage is a better approach to this problem.
- jimmaswell 5y agoA unit test covering code doesn't mean the code is actually used, and some code isn't feasible to cover in unit tests.
- p1necone 5y agoThis doesn't really help. I've found plenty of code before that isn't marked by the IDE/linters as unused because it's called by a unit test, but nothing else.
- long11l 5y agoWell atleast the code will be used then. Fingers crossed it already has a unit test, so once the dead code is remove the test can be too
- nxpnsv 5y agoIf I have tests for everything coverage is 100% regardless of whether the functions are used or not
- selcuka 5y agoIt's a pity it only supports Python >= 3.6. Large codebases with dead code are usually from the 2.7 era.
- tcbasche 5y agoIt seems a bit ... dead itself. There's a few issues there that haven't really been addressed in a long time. Definitely a cool idea though, but a little underwhelming when all it found for me was a bunch of unused variables (the boilerplate context manager arguments). And this is a fairly large Python codebase it was running over.
- caymanjim 5y agoI ran this on a Flask app. The app has no linting issues and decent test coverage. Vulture reported 192 incidences of unused methods/classes/variables/functions, all at "60% confidence" (whatever that means). There might be some legitimately-unused code in there, but this is almost entirely false positives, with the same "confidence". It seems like people build giant whitelists when using it with Flask, Django, and other frameworks. Given the volume of false positives, it seems like a maintenance burden to me. Maybe there's some trick to using it effectively, but it's not obvious to me.
- richardxia 5y agoI've had some success using it in a Django app where I generate a whitelist from my main branch, and then I run vulture on my feature branch just before I open up a pull request. This way, it doesn't matter how many false positives there are because I'm only really trying to check if my changes cause any new issues. It's still not as good as other languages with better static analysis tools, but it's better than nothing.
- petters 5y agoIn my experience, you have to set the threshold at 100%. But then it will rarely find anything. It is not essential in CI like pyflakes.
- pabs3 5y agoSome lists of links to other static analysis tools for Python: https://analysis-tools.dev/tag/python https://analysis-tools.dev/tag/python https://github.com/collab-qa/check-all-the-things/blob/master/data/python.ini https://github.com/collab-qa/check-all-the-things/blob/maste...
- maweki 5y ago> 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. Note that this problem is generally undecidable, so no tool will ever find all dead/non-dead code accurately.