from typing import List


def _append_handler_name_to_last_of_list(
        *, handler_name: str, handler_names: List[str]) -> List[str]:
    """
    Append a specified handler's name to the last of the list
    if the last one is an other handler's name.

    This function is used to unify last value regardless of
    `HandlerScope` setting.

    Parameters
    ----------
    handler_name : str
        Targer handler name.
    handler_names : list of str
        List to be appended.

    Returns
    -------
    handler_names : list of str
        Result list value.
    """
    if not handler_names:
        return [handler_name]
    if handler_names[-1] == handler_name:
        return handler_names
    handler_names.append(handler_name)
    return handler_names