def nb_language(nb, language=None):
    """Helper for fetching out the programming language from a notebook object.

    Parameters
    ----------
    nb : nbformat.NotebookNode
        The notebook to introspect
    language : str
        A provided language field

    Returns
    -------
    str
        The programming language of the notebook

    Raises
    ------
    ValueError
        If no notebook language is found or provided
    """
    language = language or nb.metadata.get('language_info', {}).get('name')
    if not language:
        # v3 language path for old notebooks that didn't convert cleanly
        language = language or nb.metadata.get('kernelspec', {}).get('language')
    if not language:
        raise ValueError("No language found in notebook and no override provided.")
    return language