In Python 2, why are instances of old style classes still instances of object
even when they do not explicitly inherit from object
?
class OldClass:
pass
>>> isinstance(OldClass(), object)
True
Before testing this, I would have concluded that isinstance(x, object) == True
would imply that x
is an instance of a subclass of object
and thus an instance of a new style class, but it appears that all objects in Python 2 are instances of object
(yes, I know how obvious that sounds).
Digging around further, I found some other seemingly odd behavior:
>>> issubclass(OldClass, object)
False
I was under the impression that isinstance(x, SomeClass)
is virtually equivalent to issubclass(x.__class__, SomeClass)
, but apparently I'm missing something.