-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for vulture
-like dead code detection
#872
Comments
By the way there is a subset of vulture (and pylint) that would be useful even without mapping out the entire codebase, namely this sort of dead-code detection: def oops():
return 1
return 2 # <- guaranteed never to run |
Yeah I'm interested in doing this. @MichaReiser shared some links with me around building these kinds of control-flow graphs. I may write it up as a more detailed issue. |
+1 we really miss this kind of linter in ruff The most interesting thing is to find those functions and classes that are forgotten and do not run |
Also +1 on linting these issues in ruff. |
+1 – would be nice. Being 100% certain about deadness of names (even locals) can be tricky – e.g. PyCharm generally highlights (well, lowlights) unused locals, unless it notices For globals, it gets even harder because a tricky user could be |
This would be extremely useful. I understand full implementation requires a lot of work, but checking if methods or variables are unused is very helpful. |
This |
Since this was opened a while ago, have there been any changes internally that would make such an implementation easier? |
Not yet. Adding multi-file analysis is a feature that's on our roadmap which will allow us to support this. |
also +1 for this feature |
If this is implemented, one kind of dead code that is not caught by vulture is when a derived class has a useless override: class Problem:
def reward_threshold(self) -> float:
"""The average return threshold at which the problem is considered solved."""
raise NotImplementedError
class BasicProblem(Problem): # This class was inserted as part of a refactor.
@override
def reward_threshold(self) -> float:
return 100.0
@dataclass
class GeometryProblem(BasicProblem):
@override
def reward_threshold(self) -> float: # Useless override — this was forgotten during the refactor.
return 100.0 |
Any updates on this? |
As a maintainer of a large Python codebase, I found
vulture
to be really useful, especially for detecting unused functions and unused modules.This would require us to introduce some new patterns and capabilities that don't yet exist in Ruff, but should! For example, we need to be able to run some analysis over every file (list the used members), then reconcile that analysis post-hoc. We also need to be able to map from references to local modules.
The text was updated successfully, but these errors were encountered: