import importlib


def get_class_from_qualname(name):
    """
    Resolve a fully qualified class name to a class, attempting any imports
    that need to be done along the way.
    :raises: ImportError or AttributeError if we can't figure out how to import it
    """
    tokens = name.split(".")
    module_name = ".".join(tokens[:-1])
    class_name = tokens[-1]

    module = importlib.import_module(module_name)
    class_ref = getattr(module, class_name)
    return class_ref