def summarize_variable(
    name: Hashable,
    var: Variable,
    col_width: int | None = None,
    max_width: int | None = None,
    is_index: bool = False,
):
    """Summarize a variable in one line, e.g., for the Dataset.__repr__."""
    variable = getattr(var, "variable", var)

    if max_width is None:
        max_width_options = OPTIONS["display_width"]
        if not isinstance(max_width_options, int):
            raise TypeError(f"`max_width` value of `{max_width}` is not a valid int")
        else:
            max_width = max_width_options

    marker = "*" if is_index else " "
    first_col = f"  {marker} {name} "
    if col_width is not None:
        first_col = pretty_print(first_col, col_width)

    if variable.dims:
        dims_str = "({}) ".format(", ".join(map(str, variable.dims)))
    else:
        dims_str = ""

    nbytes_str = f" {render_human_readable_nbytes(variable.nbytes)}"
    front_str = f"{first_col}{dims_str}{variable.dtype}{nbytes_str} "

    values_width = max_width - len(front_str)
    values_str = inline_variable_array_repr(variable, values_width)

    return front_str + values_str
Summarize a variable in one line, e.g., for the Dataset.__repr__.
xarray/core/formatting.py