def METHOD_NAME(var: Variable, spec: FormatSpec) -> str:
    if spec.has_nested or spec.has_length or spec.has_selection:
        raise ValueError(f"Invalid format spec for compact formatter: '{spec}'")
    if not _is_numeric(var.dtype):
        raise ValueError(f"Compact formatting is not supported for dtype {var.dtype}")
    values = var.values if var.shape else np.array((var.value,))
    variances = var.variances if var.shape else np.array((var.variance,))
    unt = "" if var.unit == Unit('dimensionless') else f" {var.unit}"
    # Iterate over array values to handle no- and infinite-precision cases
    if variances is None:
        formatted = [_format_element_compact(v) for v in values]
    else:
        formatted = [
            _format_element_compact(*_round(v, e)) for v, e in zip(values, variances)
        ]
    return f"{', '.join(formatted)}{unt}"