Hacker news

  • Top
  • New
  • Past
  • Ask
  • Show
  • Jobs

Show HN: Unref – A Python dead code finder built on Ruff's parser (https://github.com)

63 points by McAvey 4 days ago | 18 comments | View on ycombinator

selcuka 2 days ago |

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.

athoscouto 2 days ago |

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.

tomtom1337 2 days ago |

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 1 day ago |

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 1 day ago |

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

LaurensBER 2 days ago |

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.

neuroticnews25 2 days ago |

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

zeitlupe 2 days ago |

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

leobuskin 2 days ago |

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

casselsmarcos1 about 21 hours ago |

[flagged]

maxkaya_dev 2 days ago |

[flagged]

olk09oscar 2 days ago |

[dead]

Shexfer 2 days ago |

[flagged]

gounscrambler 2 days ago |

[flagged]

tthanh2k6 2 days ago |

[flagged]

WanderZil 2 days ago |

[dead]

musicpublisheri 2 days ago |

[flagged]