How do I check (at runtime) if one class is a subclass of another? How do I check (at runtime) if one class is a subclass of another? python python

How do I check (at runtime) if one class is a subclass of another?


You can use issubclass() like this assert issubclass(suit, Suit).


issubclass(class, classinfo)

Excerpt:

Return true if class is a subclass (direct, indirect or virtual) of classinfo.


You can use isinstance if you have an instance, or issubclass if you have a class. Normally thought its a bad idea. Normally in Python you work out if an object is capable of something by attempting to do that thing to it.