def _summarize_pattern(
    pattern: (
        tuple[int | DimVar | MultiDimVar | KnownDim, ...]
        | dict[
            named_axes.AxisName | MultiDimVar,
            int | DimVar | KnownDim | RemainingAxisPlaceholder,
        ]
    ),
) -> str:
  """Summarizes a pattern into a human-readable summary."""
  if isinstance(pattern, tuple):
    parts = []
    for dim in pattern:
      if isinstance(dim, MultiDimVar):
        parts.append(f"*var({repr(dim.name)})")
      else:
        parts.append(_show_dim(dim))
    if len(parts) == 1:
      return "(" + parts[0] + ",)"
    return "(" + ", ".join(parts) + ")"
  elif isinstance(pattern, dict):
    parts = []
    for key, val in pattern.items():
      if isinstance(key, MultiDimVar) and isinstance(
          val, RemainingAxisPlaceholder
      ):
        parts.append(f"**var({repr(key.name)})")
      else:
        parts.append(f"{repr(key)}: {_show_dim(val)}")
    return "{" + ", ".join(parts) + "}"
  else:
    raise TypeError(f"Bad pattern {pattern}")
Summarizes a pattern into a human-readable summary.
penzai/core/shapecheck.py