def _collect_indexes(
        self, indexes: Indexes
    ) -> tuple[IndexesToAlign, IndexVarsToAlign]:
        """Collect input and/or object indexes for alignment.

        Return new dictionaries of xarray Index objects and coordinate
        variables, whose keys are used to later retrieve all the indexes to
        compare with each other (based on the name and dimensions of their
        associated coordinate variables as well as the Index type).

        """
        collected_indexes = {}
        collected_index_vars = {}

        for idx, idx_vars in indexes.group_by_index():
            idx_coord_names_and_dims = []
            idx_all_dims: set[Hashable] = set()

            for name, var in idx_vars.items():
                dims = var.dims
                idx_coord_names_and_dims.append((name, dims))
                idx_all_dims.update(dims)

            key: MatchingIndexKey = (tuple(idx_coord_names_and_dims), type(idx))

            if idx_all_dims:
                exclude_dims = idx_all_dims & self.exclude_dims
                if exclude_dims == idx_all_dims:
                    # Do not collect an index if all the dimensions it uses are
                    # also excluded from the alignment
                    continue
                elif exclude_dims:
                    # If the dimensions used by index partially overlap with the dimensions
                    # excluded from alignment, it is possible to check index equality along
                    # non-excluded dimensions only. However, in this case each of the aligned
                    # objects must retain (a copy of) their original index. Re-indexing and
                    # overriding the index are not supported.
                    if self.join == "override":
                        excl_dims_str = ", ".join(str(d) for d in exclude_dims)
                        incl_dims_str = ", ".join(
                            str(d) for d in idx_all_dims - exclude_dims
                        )
                        raise AlignmentError(
                            f"cannot exclude dimension(s) {excl_dims_str} from alignment "
                            "with `join='override` because these are used by an index "
                            f"together with non-excluded dimensions {incl_dims_str}"
                            "(cannot safely override the index)."
                        )
                    else:
                        self.keep_original_indexes.add(key)

            collected_indexes[key] = idx
            collected_index_vars[key] = idx_vars

        return collected_indexes, collected_index_vars
Collect input and/or object indexes for alignment.

        Return new dictionaries of xarray Index objects and coordinate
        variables, whose keys are used to later retrieve all the indexes to
        compare with each other (based on the name and dimensions of their
        associated coordinate variables as well as the Index type).

        
xarray/structure/alignment.py