def _qualified_type_name(class_):
    """
    Compute a descriptive string representing a class, including
    a module name where relevant.

    Example outputs are "RuntimeError" for the built-in RuntimeError
    exception, or "struct.error" for the struct module exception class.

    Parameters
    ----------
    class_ : type

    Returns
    -------
    class_name : str
    """
    # We're being extra conservative here and allowing for the possibility that
    # the class doesn't have __module__ and/or __qualname__ attributes. This
    # function is called during exception handling, so we want to minimise the
    # possibility that it raises a new exception.
    class_module = getattr(class_, "__module__", "<unknown>")
    class_qualname = getattr(class_, "__qualname__", "<unknown>")
    if class_module == "builtins":
        return f"{class_qualname}"
    else:
        return f"{class_module}.{class_qualname}"