Visualize class inheritance hierarchy

Aaron "Castironpi" Brady castironpi at gmail.com
Tue Sep 23 20:22:00 EDT 2008


On Sep 23, 5:53 pm, Rob Kirkpatrick <robert.d.kirkpatr... at gmail.com>
wrote:
> Hi All,
>
> I just finished debugging some code where I needed to determine why
> one subclass had a bound method and another did not.  They had
> different pedigree's but I didn't know immediately what the
> differences were.
>
> I ended up walking the hierarchy, going back one class at a time
> through the code, for the two subclasses (hierarchy ~7 classes deep
> each) to see whom they inherited from.  Short of writing this down on
> paper, is there any way to graphically display the pedigree of an
> object/class?  "Graphically" can be text output to the terminal, don't
> need anything special...
>
> I'm assuming this has been discussed before, but I'm lacking any
> Google keywords that bring up the appropriate discussion.
>
> Cheers,
> Rob

If you're using new-style classes, check out the __mro__ member, which
no doesn't show up in its dir().  Otherwise, we can try a settrace
(frame.f_code.co_name has the name of the class being defined in a
class statement) or accumulate some class statements with a custom
'parser' run in the module 'parser'.




More information about the Python-list mailing list