I have a class named Article
in my project. I want to find all its methods that are unused in the project. For a particular method I can press Alt+F7
and see where it's used, and if it's not used anywhere, I can delete it safely. Is it possible to automate the process and find all methods of the class that are unused without pressing Alt+F7
for each method?
How to find all unused methods of a class in PyCharm?
Asked Answered
PyCharm doesn't offer this feature since it isn't possible to reliably determine that a method is unused, because there are simply too many ways to call it dynamically.
But you may use Vulture to find most of dead code in a project. Refer to the following commands:
$ pip install -U vulture
$ vulture path_of_project
$ # Use --exclude for excluding particular files (e.g. virtualenv files)
$ vulture --exclude=env path_of_project
Awesome package name. See also: #693570 –
Holdback
I just tried this out on a version 2.7 codebase, and it's not picking up completely unreferenced class methods, but giving them a 60% confidence; so Vulture does not get a very high score in my situation. Your mileage may vary. It's still a good pointer, but for me, Vulture merely gives hints. –
Gynandry
© 2022 - 2024 — McMap. All rights reserved.