code: 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]:  # type: ignore
          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]:  # type: ignore
          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))
  
imports: from __future__ import annotations
  import inspect
  import logging
  import pathlib
  import sys
  import warnings
  from typing import Any, Callable, Collection, Iterable, Literal, Optional, Type, Union, cast
  from .None import errors
  from .None import types
label_desc: Use image node_id 13 for calling a global function with example usage: validate_and_clip_range(range_vals, full_range, val_type) and returns: cast