all Python 3inspectfunction
inspect.isclass()
object kind checks
Checks that an object is a class, built-in or user-defined; an instance of a class is not a class.
Syntax
inspect.isclass(object) -> bool
A parameterized generic such as list[int] is not a class: isclass gives False even though list[int]() builds a list, because it is a types.GenericAlias. The function is equivalent to isinstance(obj, type), so a class with a metaclass passes too. Before asking 'is it a subclass' you need this check: issubclass(3, int) fails with TypeError.
Examples
import inspect
class A: pass
print(inspect.isclass(A), inspect.isclass(A())) # → True False
print(inspect.isclass(int), inspect.isclass(list[int])) # → True False
issubclass(3, int) # → TypeError: issubclass() arg 1 must be a class
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy