如何检查类型是否是Python中类型的子类型?

如何检查类型是否是Python中类型的子类型?我不是指类型的实例,而是比较类型实例本身.例如:

class A(object):
    ...

class B(A):
    ...

class C(object)
    ...

# Check that instance is a subclass instance:
isinstance(A(), A) --> True
isinstance(B(), A) --> True
isinstance(C(), A) --> False

# What about comparing the types directly?
SOME_FUNCTION(A, A) --> True
SOME_FUNCTION(B, A) --> True
SOME_FUNCTION(C, A) --> False
也许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
https://stackoverflow.com/questions/15892237/how-can-i-check-if-a-type-is-a-subtype-of-a-type-in-python

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:如何检查类型是否是Python中类型的子类型?