How do you find unused methods?

Hi all,

I love "Find usages".  Is there a way to right click in a directory and "Find unused methods" in this directory.  Basically those are the methods I want slated for deprecation?
5 comments
Comment actions Permalink
Unfortunately in Python it's not possible to reliably determine that a method is unused, because there are simply too many ways to call it dynamically. Because of that, we don't provide a batch "find unused methods" feature in PyCharm.
0
Comment actions Permalink

But why not at least have a feature that at least suggests possibly unused methods?

7
Comment actions Permalink

I'd like to have such an ability like during refactoring: split onto "direct" and "indirect", like in strings and so on. That would help detecting potential bugs when someone uses incorrect function and the correct one becomes completely unused.

2
Comment actions Permalink

It would be very convenient if there was a feature to list the functions whose name only appears in their definition i.e. if my_func only appears in "def my_func(param)". It would greatly facilitate the finding of ununsed functions.

Basically for each function/method in the file/project, it would do a search with "Match Case" and "Words" to look for all the exact occurences and if the function name appears only once, it is listed.

We could also do the same for any symbole like variables.

This feature could be named : "List symbols with one exact match". Symbol could for example be either function, method, variable or constant.

3
Comment actions Permalink

The first answer makes no sense.

PyCharm highlights unused imports, local variables and other things. They all can be accessed in non standard ways, but the highlight is very helpful.

Highlighting the unused methods would be as useful.

1

Please sign in to leave a comment.