def METHOD_NAME(rangestring: str, length: int) -> List[bool]:
    """Convert a string specifying ranges of elements, and the number of elements,
    into a list of booleans. The ranges are end-inclusive.
    >>> rangestring_to_mask("1, 3-5", 6)
    [False, True, False, True, True, True]
    >>> rangestring_to_mask("", 0)
    []
    >>> rangestring_to_mask("", 1)
    [False]
    >>> rangestring_to_mask("1", 2)
    [False, True]
    """
    mask = [False] * length
    if rangestring == "":
        # An empty string means no active indecies. Note that an
        # IndexRange-typed instance being None means the opposite
        return mask
    for _range in rangestring.split(","):
        if "-" in _range:
            if len(_range.strip().split("-")) != 2:
                raise ValueError(f"Wrong range syntax {_range}")
            start, end = map(int, _range.strip().split("-"))
            if end < start:
                raise ValueError(f"Range {start}-{end} has invalid direction")
            if end + 1 > length:
                raise ValueError(
                    f"Range endpoint {end} is beyond the mask length {length} "
                )
            mask[start : end + 1] = [True] * (end + 1 - start)
        elif _range:
            if int(_range) + 1 > length:
                raise ValueError(
                    f"Realization index {_range} is beyond the mask length {length} "
                )
            mask[int(_range)] = True
    return mask