

def sort_as_subsets(tuples, allitems):
    edges = util.defaultdict(set)
    for (parent, child) in tuples:
        edges[child].add(parent)
    todo = set(allitems)
    while todo:
        output = set()
        for node in list(todo):
            if (not todo.intersection(edges[node])):
                output.add(node)
        if (not output):
            raise CircularDependencyError('Circular dependency detected.', find_cycles(tuples, allitems), _gen_edges(edges))
        todo.difference_update(output)
        (yield output)

dataset/ETHPy150Open RoseOu/flasky/venv/lib/python2.7/site-packages/sqlalchemy/util/topological.py sort_as_subsets/original