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?
Asked
Active
Viewed 1.4k times
31

Sergey Filkin
- 475
- 1
- 6
- 10
1 Answers
46
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

Rahul Jha
- 107
- 1
- 9

JDownloader
- 566
- 4
- 7
-
2Awesome package name. See also: http://stackoverflow.com/questions/693070/how-can-you-find-unused-functions-in-python-code – Ciro Santilli OurBigBook.com Mar 27 '17 at 15:02
-
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. – Oct 31 '19 at 11:37