def is_instance_or_subclass ( val , class_ ) : try : return issubclass ( val , class_ ) except TypeError : return isinstance ( val , class_ )
python compare is instance
Return True if val is either a subclass or instance of class_ .
def is_instance_or_subclass(val, class_):
    """Return True if ``val`` is either a subclass or instance of ``class_``."""
    try:
        return issubclass(val, class_)
    except TypeError:
        return isinstance(val, class_)