Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 484
Sergey Filkin Avatar asked Nov 10 '14 08:11

Sergey Filkin


People also ask

Where are all the unused methods in IntelliJ?

Just use Analyze | Inspect Code with appropriate inspection enabled (Unused declaration under Declaration redundancy group). @CrazyCoder This shows unused fields and methods too, any way to show only unused classes? My 2 cents: on IntelliJ 2016.3. 4 the option is under Analyze > Run Inspection By Name.

How do you find the dead code in Python?

Vulture - Find dead code. Vulture finds unused code in Python programs. This is useful for cleaning up and finding errors in large code bases. If you run Vulture on both your library and test suite you can find untested code.


1 Answers

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 
like image 162
JDownloader Avatar answered Sep 18 '22 12:09

JDownloader