from typing import Sequence


def get_rank_upto(
    ranks: Sequence[str], ter_rank: str, include_terminal: bool = False
) -> Sequence[str]:
    """Generates list of ranks from `ranks` terminated at `ter_rank`

    Parameters
    ----------
    ranks
        List of ranks
    ter_rank
        Terminal rank
    include_terminal
        Include terminal/last rank or not


    Returns
    -------
    list
        List of ranks
    """
    ret = []
    tmp_ranks = list(ranks)
    if ter_rank in tmp_ranks:
        ter_index = (
            tmp_ranks.index(ter_rank) + 1
            if include_terminal
            else tmp_ranks.index(ter_rank)
        )
        if ter_index != 0:
            ret = tmp_ranks[:ter_index]
    return ret