def connection_weight(line, func):
    """
    Return the weight of the connection *line* according to weight function
    *func*.

    If *func* is None, the weight is set equal to the connection length.

    Parameters
    ----------
    line: LineString
        Geometry of the connection.
    func: function
        Function of the connection length returning its weight.

    Returns
    -------
    float
        Weight of the connection.
    """
    if func is None:
        weight = line.length
    else:
        weight = func(line.length)
    return weight
