def with_base(bases, cls):
    """
    Return a copy of bases tuple that contains the given additional class `cls`.
    """

    if cls in bases:
        return bases

    bases = list(bases)
    tail = []
    while bases:
        if issubclass(cls, bases[-1]):
            tail.append(bases.pop())
        else:
            bases.append(cls)
            break

    return (*bases, *reversed(tail))