How to find all unused methods of a class in PyCharm?
Asked Answered
T

1

31

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?

Tumid answered 10/11, 2014 at 8:39 Comment(0)
D
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
Dochandorrach answered 21/2, 2015 at 0:1 Comment(2)
Awesome package name. See also: #693570Holdback
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.