def isinstance_noimport(obj, cls_str):
    """Performs an isinstance() check using a stringified class name.

    Does not require importing the class in question, so this can be
    used to check for optional dependencies.

    """

    ty = type(obj)
    if not hasattr(ty, "__module__") or not hasattr(ty, "__qualname__"):
        return False
    return (ty.__module__ + "." + ty.__qualname__) == cls_str