(
    range_vals: Tuple[types.AnyVal, types.AnyVal],
    full_range: Tuple[types.AnyVal, types.AnyVal],
    val_type: Optional[Type[Any] | Tuple[Type[Any], ...]] = None,
)
return cast(Tuple[Any, Any], tuple(range_vals))
Validate and clip range values.

    Args:
        range_vals: Range values, i.e. [start_val, end_val), to validate
            and, if necessary, clip. If None, the value is set to the corresponding
            value in ``full_range``.
        full_range: Full range of values, i.e. [min_val, max_val),
            within which ``range_vals`` must lie.
        val_type: Type(s) of which all ``range_vals`` must be instances,
            unless val is None.

    Returns:
        Range for which null or too-small/large values have been clipped
        to the min/max valid values.

    Raises:
        TypeError
        ValueError
Validate and clip range values.
Validate and clip range values .
def validate_and_clip_range(
    range_vals: Tuple[types.AnyVal, types.AnyVal],
    full_range: Tuple[types.AnyVal, types.AnyVal],
    val_type: Optional[Type[Any] | Tuple[Type[Any], ...]] = None,
) -> Tuple[types.AnyVal, types.AnyVal]:
    """
    Validate and clip range values.

    Args:
        range_vals: Range values, i.e. [start_val, end_val), to validate
            and, if necessary, clip. If None, the value is set to the corresponding
            value in ``full_range``.
        full_range: Full range of values, i.e. [min_val, max_val),
            within which ``range_vals`` must lie.
        val_type: Type(s) of which all ``range_vals`` must be instances,
            unless val is None.

    Returns:
        Range for which null or too-small/large values have been clipped
        to the min/max valid values.

    Raises:
        TypeError
        ValueError
    """
    for range_ in (range_vals, full_range):
        if not isinstance(range_, (list, tuple)):
            raise TypeError(
                "range must be of type {}, not {}".format({list, tuple}, type(range_))
            )
        if len(range_) != 2:
            raise ValueError(
                f"range must have 2 items -- (start, end) -- not {len(range_)}"
            )
    if val_type:
        for range_ in (range_vals, full_range):
            for val in range_:
                if val is not None and not isinstance(val, val_type):
                    raise TypeError(
                        f"range value={val} must be of type {val_type}, not {type(val)}"
                    )
    if range_vals[0] is None:
        range_vals = (full_range[0], range_vals[1])
    elif range_vals[0] < full_range[0]:
        LOGGER.info(
            "start of range %s < minimum valid value %s; clipping...",
            range_vals[0],
            full_range[0],
        )
        range_vals = (full_range[0], range_vals[1])
    if range_vals[1] is None:
        range_vals = (range_vals[0], full_range[1])
    elif range_vals[1] > full_range[1]:
        LOGGER.info(
            "end of range %s > maximum valid value %s; clipping...",
            range_vals[1],
            full_range[1],
        )
        range_vals = (range_vals[0], full_range[1])
    return cast(Tuple[Any, Any], tuple(range_vals))
def validate_and_clip_range ( range_vals : Tuple [ types . AnyVal , types . AnyVal ] , full_range : Tuple [ types . AnyVal , types . AnyVal ] , val_type : Optional [ Type [ Any ] | Tuple [ Type [ Any ] , ... ] ] = None , ) -> Tuple [ types . AnyVal , types . AnyVal ] : for range_ in ( range_vals , full_range ) : if not isinstance ( range_ , ( list , tuple ) ) : raise TypeError ( "range must be of type {}, not {}" . format ( { list , tuple } , type ( range_ ) ) ) if len ( range_ ) != 2 : raise ValueError ( f"range must have 2 items -- (start, end) -- not {len(range_)}" ) if val_type : for range_ in ( range_vals , full_range ) : for val in range_ : if val is not None and not isinstance ( val , val_type ) : raise TypeError ( f"range value={val} must be of type {val_type}, not {type(val)}" ) if range_vals [ 0 ] is None : range_vals = ( full_range [ 0 ] , range_vals [ 1 ] ) elif range_vals [ 0 ] < full_range [ 0 ] : LOGGER . info ( "start of range %s < minimum valid value %s; clipping..." , range_vals [ 0 ] , full_range [ 0 ] , ) range_vals = ( full_range [ 0 ] , range_vals [ 1 ] ) if range_vals [ 1 ] is None : range_vals = ( range_vals [ 0 ] , full_range [ 1 ] ) elif range_vals [ 1 ] > full_range [ 1 ] : LOGGER . info ( "end of range %s > maximum valid value %s; clipping..." , range_vals [ 1 ] , full_range [ 1 ] , ) range_vals = ( range_vals [ 0 ] , full_range [ 1 ] ) return cast ( Tuple [ Any , Any ] , tuple ( range_vals ) )