code: def topologically_sorted_indexes(self):
          
          try:
              return self._topologcally_sorted_indexes_cache
          except AttributeError:
              seen = set()
              order = []
              explored = set()
  
              for i in self.edges:
                  if i in explored:
                      continue
                  fringe = [i]
                  while fringe:
                      w = fringe[-1]  # depth first search
                      if w in explored:  # already looked down this branch
                          fringe.pop()
                          continue
                      seen.add(w)  # mark as seen
                      # Check successors for cycles and for new nodes
                      new_nodes = []
                      for n in self.outputs_of(w):
                          if n not in explored:
                              if n in seen:  # CYCLE !!
                                  raise RuntimeError("Graph contains a cycle.")
                              new_nodes.append(n)
                      if new_nodes:  # Add new_nodes to fringe
                          fringe.extend(new_nodes)
                      else:  # No new nodes so w is fully explored
                          explored.add(w)
                          order.append(w)
                          fringe.pop()  # done considering this node
              self._topologcally_sorted_indexes_cache = tuple(filter(lambda i: type(i) is int, reversed(order)))
              return self._topologcally_sorted_indexes_cache
docs: Iterate in topological order, based on networkx's topological_sort() function.