class_docstr: Provides functionality to topologically sort a graph of hashable nodes
docstr: Mark the graph as finished and check for cycles in the graph.
  
  If any cycle is detected, "CycleError" will be raised, but "get_ready" can
  still be used to obtain as many nodes as possible until cycles block more
  progress. After a call to this function, the graph cannot be modified and
  therefore no more nodes can be added using "add".
docstr_tok: ["Mark","the","graph","as","finished","and","check","for","cycles","in","the","graph",".","If","any","cycle","is","detected",",","``","CycleError","''","will","be","raised",",","but","``","get_ready","''","can","still","be","used","to","obtain","as","many","nodes","as","possible","until","cycles","block","more","progress",".","After","a","call","to","this","function",",","the","graph","can","not","be","modified","and","therefore","no","more","nodes","can","be","added","using","``","add","''","."]
code: def prepare(self):
      """Mark the graph as finished and check for cycles in the graph.
  
      If any cycle is detected, "CycleError" will be raised, but "get_ready" can
      still be used to obtain as many nodes as possible until cycles block more
      progress. After a call to this function, the graph cannot be modified and
      therefore no more nodes can be added using "add".
      """
      if self._ready_nodes is not None:
          raise ValueError("cannot prepare() more than once")
  
      self._ready_nodes = [
          i.node
          for i in self._node2info.values()
          if i.npredecessors == 0
      ]
      # ready_nodes is set before we look for cycles on purpose:
      # if the user wants to catch the CycleError, that's fine,
      # they can continue using the instance to grab as many
      # nodes as possible before cycles block more progress
      cycle = self._find_cycle()
      if cycle:
          raise CycleError(f"nodes are in a cycle", cycle)
  
file_path: catboost/contrib/tools/python3/src/Lib/graphlib.py
imports: from types import GenericAlias
label_desc: Use image node_id 4 for calling the TopologicalSorter obj's underlying member method code with example usage: obj.prepare() without return types