human
I wrote the below code

    if (not G.is_directed()):
        raise nx.NetworkXError('Topological    sort    not    defined    on    undirected    graphs.')
    if (key is None):
        key = (lambda x: x)
    def create_tuple(node):
        return (key(node), node)
    indegree_map = {v: d for (v, d) in G.in_degree() if (d > 0)}
    zero_indegree = [create_tuple(v) for (v, d) in G.in_degree() if (d == 0)]
    heapq.heapify(zero_indegree)
    while zero_indegree:
        (_, node) = heapq.heappop(zero_indegree)
        if (node not in G):
            raise RuntimeError('Graph    changed    during    iteration')
        for (_, child) in G.edges(node):
            try:
                indegree_map[child] -= 1
            except KeyError:
                raise RuntimeError('Graph    changed    during    iteration')
            if (indegree_map[child] == 0):
                heapq.heappush(zero_indegree, create_tuple(child))
                del indegree_map[child]
        (yield node)
    if indegree_map:
        raise nx.NetworkXUnfeasible('Graph    contains    a    cycle    or    graph    changed    during    iteration')

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

def lexicographical_topological_sort(G, key=None):