How can I check if a type is a subtype of a type in Python? -
how can check if type subtype of type in python? not referring instances of type, comparing type instances themselves. example:
class a(object): ... class b(a): ... class c(object) ... # check instance subclass instance: isinstance(a(), a) --> true isinstance(b(), a) --> true isinstance(c(), a) --> false # comparing types directly? some_function(a, a) --> true some_function(b, a) --> true some_function(c, a) --> false
maybe issubclass?
>>> class a(object): pass >>> class b(a): pass >>> class c(object): pass >>> issubclass(a, a) true >>> issubclass(b, a) true >>> issubclass(c, a) false
Comments
Post a Comment