code: def _assert_same_base_type(items, expected_type=None):
      r"""Asserts all items are of the same base type.
  
      Args:
        items: List of graph items (e.g., `Variable`, `Tensor`, `SparseTensor`,
            `Operation`, or `IndexedSlices`). Can include `None` elements, which
            will be ignored.
        expected_type: Expected type. If not specified, assert all items are
            of the same base type.
  
      Returns:
        Validated type, or none if neither expected_type nor items provided.
  
      Raises:
        ValueError: If any types do not match.
      """
      original_expected_type = expected_type
      mismatch = False
      for item in items:
          if item is not None:
              item_type = base_dtype(item.dtype)
              if expected_type is None:
                  expected_type = item_type
              elif expected_type != item_type:
                  mismatch = True
                  break
      if mismatch:
          # Loop back through and build up an informative error message (this is very
          # slow, so we don't do it unless we found an error above).
          expected_type = original_expected_type
          original_item_str = None
          get_name = lambda x: x.name if hasattr(x, "name") else str(x)
          for item in items:
              if item is not None:
                  item_type = base_dtype(item.dtype)
                  if not expected_type:
                      expected_type = item_type
                      original_item_str = get_name(item)
                  elif expected_type != item_type:
                      raise ValueError(
                          "{}, type={}, must be of the same type ({}){}.".format(
                              get_name(item),
                              item_type,
                              expected_type,
                              (
                                  (" as {}".format(original_item_str))
                                  if original_item_str
                                  else ""
                              ),
                          )
                      )
          return expected_type  # Should be unreachable
      else:
          return expected_type
  
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow.python.util import nest
label_desc: Use image node_id 17 for calling a global function with example usage: _assert_same_base_type(items, expected_type) and returns: expected_type, expected_type