Why does type(object) return <class 'type'> instead of <class 'object'>?

Viewed 395

I was playing around in REPL and noticed behavior regarding the built-in object base class that confuses me:

>>> object
<class 'object'>
>>> type(object)
<class 'type'>

Why is the type of object in this case not <class 'object'>? What's happening here?

1 Answers

Classes are always, directly (implicit in all classes without a declared metaclass) or indirectly (via metaclasses, which are always subclasses of type), instances of type. object itself is a class, you didn't make an instance of it, so it can't report itself to be an instance of object (not directly anyway; isinstance(object, object) does return True, because everything, including type itself, is an instance of object if you follow the inheritance chain far enough).

If you'd made an instance of object, e.g. type(object()), it would report what you expected.

Related