Where is it inherited from?

When debugging in python, it’s sometimes difficult to figure out where to look for the definition of an instance method. It could be inherited from a more top level class in the inheritance tree, it may be a hook/patch or the result of acquisition.

Here’s a solution that works in most cases:

some_instance.mistery_method() # ?? where is it defined
some_instance.mistery_method.im_func.func_code.co_filename # here you get the source filename
some_instance.mistery_method.im_func.func_code.co_firstlineno # and the line number.

Smooth, ain’t it?