Show HN: Unref – A Python dead code finder built on Ruff's parser

McAvey 63 points 18 comments November 16, 2026
github.com · View on Hacker News

I wanted a good Python dead code finder that just works, with minimal config, until Ruff adds support for that ( https://github.com/astral-sh/ruff/issues/872 ). 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.

Discussion Highlights (9 comments)

leobuskin

All of CPython’s stdlib, right? It’s Python dead code checker, not C.

LaurensBER

Thanks, this seems like a very good approach and is indeed very fast! Happy to run this over our codebase and see how it compares against Vulture.

selcuka

Cool project. I think false positives are more important than the dead code it misses at this stage. For example, it marks all Django settings as unused variables, probably because settings are typically not imported directly in Django projects. For example: 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.

neuroticnews25

It listed 204 unused functions in my flask project, most or all of them are false positives, and I don't do anything magical.

athoscouto

I've been trying to do something like this internally too. Also started with Python, then moved onto ruff. My goal is a bit broader though. I want to use the dependency graph to detect changed parts of the project to selectively trigger image builds and run tests. 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.

zeitlupe

Thanks! I just tried it, it is definitely incredibly fast. Found a couple of true positives, too.

tomtom1337

What is the definition of dead code that Unref uses? I distinguish between apps and libraries. In apps I can see how any code not callable from the entrypoint is dead, and for libraries I guess a definition is any code that is not callable from a public api? Would be nice to see the definition used placed in the docs/github readme.

peterabbitcook

Did you compare what you’ve built to some of the internals of nuitka? nuitka stops dead code search at the module level, but their exclusion/inclusion flags/rules might steer you towards fewer false positives for common packages.

vrighter

i see lots of projects for python that spend a ton of duplicated effort trying to make an imperfect tool for something that in other languages can be done reliably with a single keystroke. python resists tooling

Semantic search powered by Rivestack pgvector
3,874 stories · 35,194 chunks indexed