If instead of discovery of the baseclass (i.e reflection) you know the desired class in advance you could use the following built in functions
eg:
# With classes from original Question defined
>>> instance = A()
>>> B_instance = B()
>>> isinstance(instance, A)
True
>>> isinstance(instance, B)
False
>>> isinstance(B_instance, A) # Note it returns true if instance is a subclass
True
>>> isinstance(B_instance, B)
True
>>> issubclass(B, A)
True
isinstance( object, classinfo)
Return true if the object argument is an instance of the classinfo
argument, or of a (direct or indirect)
subclass thereof. Also return true if
classinfo is a type object and object
is an object of that type. If object
is not a class instance or an object
of the given type, the function always
returns false. If classinfo is neither
a class object nor a type object, it
may be a tuple of class or type
objects, or may recursively contain
other such tuples (other sequence
types are not accepted). If classinfo
is not a class, type, or tuple of
classes, types, and such tuples, a
TypeError exception is raised. Changed
in version 2.2: Support for a tuple of
type information was added.
issubclass( class, classinfo)
Return true if class is a subclass (direct or indirect) of classinfo. A
class is considered a subclass of
itself. classinfo may be a tuple of
class objects, in which case every
entry in classinfo will be checked. In
any other case, a TypeError exception
is raised. Changed in version 2.3:
Support for a tuple of type
information was added.