Perhaps this is a trivial question. under python, how come self.__class__.__bases__ doesn't trace back to object? Mine only shows a tuple of the one single parent above the class.
self.__class__.__bases__ only goes "one level up" in class inheritance. If you want to trace all the way through every parent class up to object, use self.__class__.__mro__.
__bases__essentially contains the base-classes passed to the metaclass constructor.
So a class definition statement like:
class Foo(Bar, Baz):
pass
Is essentially equivalent to:
Foo = type("Foo", (Bar, Baz), {})
So the __bases__ attribute is essentially the value to the bases argument of the type constructor: type(object_or_name, bases, dict)
If you want the entire inheritance chain, you should use:
self.__class__.mro()
To read a little bit more about the internals of class creating, read about metaclasses, section 3.3.3.1 to 3.3.3.6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With