Python 2.6: Determining if a method is inherited

Valentino Volonghi aka Dialtone dialUAZ###UZ#$AAtone at
Sun Oct 5 21:15:36 CEST 2008

Fuzzyman <fuzzyman at> wrote:

> So how do I tell if the X.__lt__ is inherited from object? I can look

I don't have python 2.6 installed so I can't try but what I think could
work is:

>>> class Foo(object):
...     def hello(self):
...         pass
>>> class Bla(Foo):
...     def hello(self):
...         pass
>>> class Baz(Foo):
...     pass
>>> Baz.hello.im_func
<function hello at 0x2b1630>
>>> Bla.hello.im_func
<function hello at 0x2b1670>
>>> Foo.hello.im_func
<function hello at 0x2b1630>
>>> Foo.hello.im_func is Baz.hello.im_func
>>> Foo.hello.im_func is Bla.hello.im_func

Which to me also makes sense. If it's inherited I expect it to be the
very same function object of one of the bases (which you can get with
inspect.getmro(Clazz)). On the other end if you override it it's not the
same function object so it won't return True when applied to 'is'.


Valentino Volonghi aka Dialtone -- Aperiodico di resistenza informatica
Public Beta:

More information about the Python-list mailing list