from typing import List
from typing import Any
from typing import Optional


def data_is_inconsistent_length(
    rows: List[List[Any]], labels: Optional[List[Any]] = None
):
    """Ensure all rows have the same length and labels match as well if provided.

    :param rows: 2D list containing objects that have a single-line representation (via `str`).
    All rows must be of the same length.
    :param labels: List containing the column labels., defaults to None
    :return: Message if there is an error, False if data is consistent
    :rtype: bool, False
    """
    n_columns = len(rows[0])

    if not n_columns:
        return "No data provided"

    for i, row in enumerate(rows):
        if len(row) != n_columns:
            return f"Inconsistent number of rows, line {i} does not match first row"

    if labels and len(labels) != n_columns:
        return f"Number of labels {len(labels)} does not match columns in first row {n_columns}"

    return False