Similar to isinstance, but if 'typ' is a parametrized generic Type, it is first transformed into its base generic
    class so that the instance check works. It is also robust to Union and Any.

    :param inst:
    :param typ:
    :return:

def robust_isinstance(inst, typ) -> bool:
    """
    Similar to isinstance, but if 'typ' is a parametrized generic Type, it is first transformed into its base generic
    class so that the instance check works. It is also robust to Union and Any.

    :param inst:
    :param typ:
    :return:
    """
    if typ is Any:
        return True
    if is_typevar(typ):
        if hasattr(typ, '__constraints__') and typ.__constraints__ is not None:
            typs = get_args(typ, evaluate=True)
            return any(robust_isinstance(inst, t) for t in typs)
        elif hasattr(typ, '__bound__') and typ.__bound__ is not None:
            return robust_isinstance(inst, typ.__bound__)
        else:
            # a raw TypeVar means 'anything'
            return True
    else:
        if is_union_type(typ):
            typs = get_args(typ, evaluate=True)
            return any(robust_isinstance(inst, t) for t in typs)
        else:
            return isinstance(inst, get_base_generic_type(typ))