I know that in Python, given a class ClassA
, with
inspect.getmembers(ClassA, predicate=inspect.ismethod)
I can iterate over the different methods present in ClassA
. Inherited methods are also gathered, which is convenient in my case. But what I would need is, given a particular method method1
of ClassA
, to get the class from which ClassA
inherited method1
. It might be ClassA
itself, or any of its parents/grandparents. I thought I could recursively traverse the __bases__
attribute, looking for the method1
attribute at each step. But maybe this functionality is already implemented somewhere. Is there another way?