human
Here's a good function header given the following:
I wrote the below code

    if (not is_partition(G, communities)):
        raise NotAPartition(G, communities)
    multigraph = G.is_multigraph()
    directed = G.is_directed()
    m = G.size(weight=weight)
    if directed:
        out_degree = dict(G.out_degree(weight=weight))
        in_degree = dict(G.in_degree(weight=weight))
        norm = (1 / m)
    else:
        out_degree = dict(G.degree(weight=weight))
        in_degree = out_degree
        norm = (1 / (2 * m))
    def val(u, v):
        try:
            if multigraph:
                w = sum((d.get(weight, 1) for (k, d) in G[u][v].items()))
            else:
                w = G[u][v].get(weight, 1)
        except KeyError:
            w = 0
        if ((u == v) and (not directed)):
            w *= 2
        return (w - ((in_degree[u] * out_degree[v]) * norm))
    Q = sum((val(u, v) for c in communities for (u, v) in product(c, repeat=2)))
    return (Q * norm)

What's a good function header?
assistant
#Here's a good function header.

def modularity(G, communities, weight='weight'):