code: def _check_data_and_mesh_compat(mesh: PolyMesh, data: PolyData):
      """Check that mesh and data have the same keys and that shapes match."""
      data_keys, mesh_keys = set(data.keys()), set(mesh.keys())
      if data_keys != mesh_keys:
          diff = data_keys.symmetric_difference(mesh_keys)
          raise ValueError(
              "Data and mesh do not have the same keys. "
              f"Offending keys: {diff}"
          )
      for key in mesh_keys:
          if data[key].shape[-1] != mesh[key].n_vertices:
              raise ValueError(
                  "Data shape does not match number of vertices"
                  f" for '{key}':"
                  f"\ndata shape: {data[key].shape}",
                  f"\nn vertices: {mesh[key].n_vertices}",
              )
  
imports: from __future__ import annotations
  import abc
  import dataclasses
  import pathlib
  from typing import Dict
  import numpy
  from nilearn.experimental.surface import _io
label_desc: Use image node_id 2 for calling a global function with example usage: _check_data_and_mesh_compat(mesh, data) without return types