Given a class Foo
(whether it is a new-style class or not), how do you generate all the base classes - anywhere in the inheritance hierarchy -
See the __bases__ property available on a python class
, which contains a tuple of the bases classes:
>>> def classlookup(cls):
... c = list(cls.__bases__)
... for base in c:
... c.extend(classlookup(base))
... return c
...
>>> class A: pass
...
>>> class B(A): pass
...
>>> class C(object, B): pass
...
>>> classlookup(C)
[<type 'object'>, <class __main__.B at 0x00AB7300>, <class __main__.A at 0x00A6D630>]