from typing import List
from typing import Set


def _extract_target_labels(targets_in_order: List[dict], target_name: str) -> Set[str]:
    """Collect a set of all the board names from the inherits field in each target in the hierarchy.

    Args:
        targets_in_order: list of targets in order of inheritance, starting with the target up to its highest ancestor
        target_name: the name of the target to find the labels for

    Returns:
        A set of names of boards that make up the inheritance tree for the target
    """
    labels = {target_name}
    for target in targets_in_order:
        for parent in target.get("inherits", []):
            labels.add(parent)
    return labels