from typing import List


def assert_optional_type_hints(contents: List[str]) -> List[str]:
    """
    Find parameters with default value None and add Optional[type] to them.

    :param contents: list of lines in file
    :return: list of lines in file
    """

    i = 0
    while i < len(contents) - 1:
        line = contents[i].strip()

        if line.startswith("def"):
            end_index = i
            while not line.endswith(":"):
                end_index += 1
                line = contents[end_index].strip()

            parameters_text = "".join(contents[i:end_index+1]).replace('\n', ' ')
            parameters_text = parameters_text[parameters_text.find("(") + 1 : parameters_text.rfind(")")]
            parameters = [param.strip() for param in parameters_text.split(",") if param.strip() and not param.strip().endswith("]")]

            # find the parameters with default value None
            parameters_with_default_value_none = [
                parameter
                for parameter in parameters
                if "= None" in parameter
            ]
            # add Optional[type] to parameters with default value None
            for parameter in parameters_with_default_value_none:
                parameter_name = parameter.split(":")[0].strip()
                parameter_type = parameter.split(":")[1].strip()
                parameter_type = parameter_type.replace("= None", "").rstrip()
                for j in range(i, end_index + 1):
                    contents[j] = contents[j].replace(
                        parameter, f"{parameter_name}: Optional[{parameter_type}] = None"
                    )

        i += 1

    return contents