import inspect


def classname(val):
    """ Returns a qualified class name as string.

    The qualified class name consists of the module and the class name,
    separated by a dot. If an instance is passed to this function, the name
    of its class is returned.

    Parameters
    ----------
    val : instance or class
        The instance or a class of which the qualified class name is returned.

    Returns
    -------
    str : The qualified class name.
    """
    if inspect.isclass(val):
        return ".".join([val.__module__,
                         val.__name__])
    return ".".join([val.__class__.__module__,
                     val.__class__.__name__])