I thought that specific types were subclasses of type
They aren't. Every class is an instance of type
; type
acts as the class for classes. isinstance(class, type)
returns True
while issubclass
correctly returns False
.
A case where issubclass
returns True
is with custom meta-classes (class of classes) that actually inherit from type
. For example, take EnumMeta
:
>>> from enum import EnumMeta
>>> issubclass(EnumMeta, type)
This is True
because EnumMeta
has type
as a base class (inherits from it):
>>> EnumMeta.__bases__
(type,)
if you looked its source up you'd see it's defined as class EnumMeta(type): ...
.
issubclass(type, object)
returns True
for everything because every single thing in Python is an object (meaning everything inherits from object
).