How to find methods which are only defined in a subclass, in Python 2.7?
<p>Is there a clean way to get methods only defined in a subclass that not defined in parent class?</p>

<pre><code>class Parent(object):
     def method_of_parent(self):
         pass
class SubClass(Parent):
     def method_of_subclass(self):
         pass

# desired:
&gt;&gt;&gt; print(get_subclass_methods(SubClass))
['method_of_subclass',]
</code></pre>

<p>I think there are many corner cases but here is one of solutions.</p>

<pre><code>import inspect


class Parent(object):
     def method_of_parent(self):
         pass
class SubClass(Parent):
     def method_of_subclass(self):
         pass

def get_subclass_methods(child_cls):
    parents = inspect.getmro(child_cls)[1:]
    parents_methods = set()
    for parent in parents:
        members = inspect.getmembers(parent, predicate=inspect.ismethod)
        parents_methods.update(members)

    child_methods = set(inspect.getmembers(child_cls, predicate=inspect.ismethod))

    child_only_methods = child_methods - parents_methods
    return [m[0] for m in child_only_methods]

print(get_subclass_methods(SubClass))
</code></pre>

<p>Result</p>

<pre><code>['method_of_subclass']
</code></pre>

python python-2.7 methods subclass