Skip to main content
added 87 characters in body
Source Link
Antti Haapala
  • 134.7k
  • 23
  • 296
  • 348

Every class of objects in Python inherits the behaviours of the object class. Firstly, it means that

>>> isinstance(x, object)
True

will be true in Python 3 no matter what x happens to be bound to. It also means that everything will also inherit the methods of the object as such, unless overridden by a more specific class. Thus, x == y will resort to object.__eq__ if neither of x or y overrode the __eq__ method.

type in Python 3 is also an object - it inherits from object:

>>> isinstance(type, object)
True

It means that type is an object, and it has inherited the behaviour from the object class. That is what enables one to write things like

>>> type == type
True
>>> type.__eq__
<slot wrapper '__eq__' of 'object' objects>

The type.__eq__ was inherited from the object class.

But the object class itself is also a type:

>>> isinstance(object, type)
True

It means that the class object as an object inherits the behaviour of type - type is object's metaclass.

And of course type's metaclass is type:

>>> isinstance(type, type)
True

And the class object is an object too:

>>> isinstance(object, object)
True

When you construct an instance of class, the class itself is responsible for both the meat and bones for that class, but perhaps one could put the distinction in that the meatbones follows the ordinary class inheritance, and bones followmeat is split between the class and the metaclass lineagelineage; and the metaclass is also the bones for the class object itself.

Every class of objects in Python inherits the behaviours of the object class. Firstly, it means that

>>> isinstance(x, object)
True

will be true in Python 3 no matter what x happens to be bound to. It also means that everything will also inherit the methods of the object as such, unless overridden by a more specific class. Thus, x == y will resort to object.__eq__ if neither of x or y overrode the __eq__ method.

type in Python 3 is also an object - it inherits from object:

>>> isinstance(type, object)
True

It means that type is an object, and it has inherited the behaviour from the object class. That is what enables one to write things like

>>> type == type
True
>>> type.__eq__
<slot wrapper '__eq__' of 'object' objects>

The type.__eq__ was inherited from the object class.

But the object class itself is also a type:

>>> isinstance(object, type)
True

It means that the class object as an object inherits the behaviour of type - type is object's metaclass.

And of course type's metaclass is type:

>>> isinstance(type, type)
True

And the class object is an object too:

>>> isinstance(object, object)
True

When you construct an instance of class, the class itself is responsible for both the meat and bones for that class, but perhaps one could put the distinction in that the meat follows the ordinary class inheritance, and bones follow the metaclass lineage.

Every class of objects in Python inherits the behaviours of the object class. Firstly, it means that

>>> isinstance(x, object)
True

will be true in Python 3 no matter what x happens to be bound to. It also means that everything will also inherit the methods of the object as such, unless overridden by a more specific class. Thus, x == y will resort to object.__eq__ if neither of x or y overrode the __eq__ method.

type in Python 3 is also an object - it inherits from object:

>>> isinstance(type, object)
True

It means that type is an object, and it has inherited the behaviour from the object class. That is what enables one to write things like

>>> type == type
True
>>> type.__eq__
<slot wrapper '__eq__' of 'object' objects>

The type.__eq__ was inherited from the object class.

But the object class itself is also a type:

>>> isinstance(object, type)
True

It means that the class object as an object inherits the behaviour of type - type is object's metaclass.

And of course type's metaclass is type:

>>> isinstance(type, type)
True

And the class object is an object too:

>>> isinstance(object, object)
True

When you construct an instance of class, the class itself is responsible for both the meat and bones for that class, but perhaps one could put the distinction in that the bones follows the ordinary class inheritance, and meat is split between the class and the metaclass lineage; and the metaclass is also the bones for the class object itself.

Source Link
Antti Haapala
  • 134.7k
  • 23
  • 296
  • 348

Every class of objects in Python inherits the behaviours of the object class. Firstly, it means that

>>> isinstance(x, object)
True

will be true in Python 3 no matter what x happens to be bound to. It also means that everything will also inherit the methods of the object as such, unless overridden by a more specific class. Thus, x == y will resort to object.__eq__ if neither of x or y overrode the __eq__ method.

type in Python 3 is also an object - it inherits from object:

>>> isinstance(type, object)
True

It means that type is an object, and it has inherited the behaviour from the object class. That is what enables one to write things like

>>> type == type
True
>>> type.__eq__
<slot wrapper '__eq__' of 'object' objects>

The type.__eq__ was inherited from the object class.

But the object class itself is also a type:

>>> isinstance(object, type)
True

It means that the class object as an object inherits the behaviour of type - type is object's metaclass.

And of course type's metaclass is type:

>>> isinstance(type, type)
True

And the class object is an object too:

>>> isinstance(object, object)
True

When you construct an instance of class, the class itself is responsible for both the meat and bones for that class, but perhaps one could put the distinction in that the meat follows the ordinary class inheritance, and bones follow the metaclass lineage.