Let's say I have the following code:
class A:
pass
class B(A):
pass
class C(B):
pass
obj = C()
Then, obj
is an instance of all three classes A
, B
, and C
. This can be verified by calling isinstance(obj, cls)
.
Is there a way to do the inverse, that is to have a function which returns a list of all classes that an object is an instance of?
So, isinstanceof(obj)
would return [A, B, C]
.