In Python 2.x, all new-style classes inherit from object
implicitly or explicitly. Then look at this:
>>> class M(type):
... pass
...
>>> class A:
... __metaclass__ = M
...
>>> class B:
... pass
...
>>> a = A()
>>> b = B()
>>> type(A)
<class '__main__.M'>
>>> type(a)
<class '__main__.A'>
Does this mean A
is a new-style class? But A
doesn't inherit from object
anyway, right?
>>> type(B)
<class 'classobj'>
>>> type(b)
<type 'instance'>
OK, B
is a classic class, isn't it?
>>> isinstance(A, object)
True
>>> isinstance(B, object)
True
why are instances of both A
and B
instances of object
?
If B
is an instance of object
, then type(B)
wouldn't be classobj
, right?