logoalt Hacker News

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

31 points • by McAvey • last Monday at 1:30 PM • 5 comments • view on HN

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.


Comments

selcuka • today at 9:34 AM

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.

LaurensBER • today at 9:28 AM

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.

➕ show 1 reply
leobuskin • today at 9:09 AM

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

➕ show 1 reply
olk09oscar • today at 10:22 AM

[dead]

maxkaya_dev • today at 10:03 AM

[flagged]

gounscrambler • today at 6:51 AM

[flagged]

musicpublisheri • today at 6:45 AM

[flagged]