How to examine the inheritance of a class?

Craig Allen callen314 at gmail.com
Sat Oct 25 01:02:38 CEST 2008


> Thank you, Chris.  Class.__bases__ is exactly what I wanted to see.
> And I thought I had tried isinstance(), and found it lacking -- but I
> just tried it again, and it does what I hoped it would do.

While isinstance is no doubt the proper way to access this
information, you may have run into problems because that isinstance
and ducktyping do not always work well together... because having a
particular interface does not mean you inherited that interface.
Checking __bases__ will not solve the problem either though, so best
to use isinstance if you can and document what you do well enough to
help people avoid breaking the assumptions of your system.

not that you didn't know that... but I thought it was worth saying
because I, at least, more and more do meta-class style techniques
which unfortunately do not play well with certain methods of checking
type.

-cba






More information about the Python-list mailing list