def call_option_function(option, flight):
    """
    Call the function associated with the specified option

    :param option: Option definiton (dictionary)
    :param flight: Current flight object
    :raises ValueError: If the callback function requires a flight object and the passed instance is None
    :return: Either a new flight or the current flight object
    """
    if option["has_flight_parameter"]:
        if flight:
            result = option["function"](flight=flight)
        else:
            raise ValueError(f"'{option['description']}' requires a valid flight")
    else:
        result = option["function"]()

    # In the context of the unit tests, isinstance() fails so just compare the type name
    return result if type(result).__name__ == "Flight" else flight