I've been reading about metaclasses and I got lost when it came to type
and object
classes.
I understand that they are at the top of the hierarchy and they are implemented in C code.
I also understand that type
inherits from object
and that object
is an instance of type
.
In one of the answers I've found on SO, someone said - in reagards to object-type
relationship - that:
This kind of mutual inheritance is not normally possible, but that's the way it is for these fundamental types in Python: they break the rules.
My question is why is it implemented this way, what is purpose of such implementation? What problems does it solve/what are the benefits of this design? Couldn't it be just type
or just object
class that is at the top of the hierarchy that every class inherits from?
Finally, is there any difference between subclassing from object
vs subclassing from type
, and when would I want to use one over the other?
class Foo(object):
pass
vs
class Foo(type):
pass