from typing import List
from typing import Tuple


def get_new_gatecharacterization_range(
    current_valid_ranges: List[Tuple[float, float]],
    safety_voltage_ranges: List[Tuple[float, float]],
    range_update_directives: List[str],
) -> List[Tuple[float, float]]:
    """Determines new voltage range for a subsequent tuning stage
    iteration. It extends the current range to the relevant safety range, i.e.
    if the directive required a voltage to be swept more negative, then the
    lower bound is set to the lower safety value.
    No intermediate tries, just being efficient.

    Args:
        current_valid_ranges: Current voltage ranges.
        safety_voltage_ranges: List of safety ranges.
        range_update_directives: List of range update directives.

    Returns:
        list: List with a tuple with the new voltage range.
    """

    assert len(current_valid_ranges) == 1
    assert len(safety_voltage_ranges) == 1

    new_min, new_max = current_valid_ranges[0]
    safety_range = safety_voltage_ranges[0]

    for directive in range_update_directives:
        if directive not in ["x more negative", "x more positive"]:
            raise KeyError("Unknown voltage range update directive.")

    if "x more negative" in range_update_directives:
        new_min = safety_range[0]
    if "x more positive" in range_update_directives:
        new_max = safety_range[1]

    return [(new_min, new_max)]