See all callers of all methods of a class

I'm aware that I can use 'Find Usages' to find what's calling a method on a class.
Is there a way of doing this for all methods on a given class? (or indeed all methods in file) 

Use Case: I'm trying to refactor a god class, that should almost certainly be several classes. It would be nice to be able to see what subset of god class methods, the classes that interact with it use. It seems like PyCharm has done the hard bit of this, but doesn't let me scale it up.  

I'm using PyCharm 2016.1.2

2 comments

This is possible, but you have to deal with abstraction otherwise Pycharm doesn't know the method in question belongs to your specific class. AKA - Type Hinting

Any instance of that method being called in an abstraction layer which does not have type hinting will not be found.

Example:

#The class which has the method you're searching for.
class Inst(object):
    def mymethod(self):
        return

#not the class your looking for, but it too has a method of the same name.
class SomethingElse(object):
    def mymethod(self):
        return

#Option 1 -- Assert hinting
def foo(inst):
    assert isinstance(inst, Inst)
    inst.mymethod()

#Option 2 --  docstring hinting
def bar(inst):
    """

    :param inst: 
    :type inst: Inst 
    :return: 
    :rtype: 
    """
    inst.mymethod()
0

Please sign in to leave a comment.