At runtime, I want to check whether a specified child class is derived from a specified parent class.
With an object instance, it's easy:
def is_related(child_instance, parent_type):
return isinstance(child_instance, parent_type)
Is there some way to do this without having (or creating) an instance of the child but, instead, having a reference to the child's type?
Something like...
def is_related(child_type, parent_type):
return is_child_class(child_type, parent_type)
Provide an implementation for is_child_class
will answer this question.
(By comparison, types in C# know about their supertypes. I don't know whether this is also true in Python.)