class_docstr: Provides functionality to topologically sort a graph of hashable nodes
docstr: Add a new node and its predecessors to the graph.
  
  Both the *node* and all elements in *predecessors* must be hashable.
  
  If called multiple times with the same node argument, the set of dependencies
  will be the union of all dependencies passed in.
  
  It is possible to add a node with no dependencies (*predecessors* is not provided)
  as well as provide a dependency twice. If a node that has not been provided before
  is included among *predecessors* it will be automatically added to the graph with
  no predecessors of its own.
  
  Raises ValueError if called after "prepare".
docstr_tok: ["Add","a","new","node","and","its","predecessors","to","the","graph",".","Both","the","*","node","*","and","all","elements","in","*","predecessors","*","must","be","hashable",".","If","called","multiple","times","with","the","same","node","argument",",","the","set","of","dependencies","will","be","the","union","of","all","dependencies","passed","in",".","It","is","possible","to","add","a","node","with","no","dependencies","(","*","predecessors","*","is","not","provided",")","as","well","as","provide","a","dependency","twice",".","If","a","node","that","has","not","been","provided","before","is","included","among","*","predecessors","*","it","will","be","automatically","added","to","the","graph","with","no","predecessors","of","its","own",".","Raises","ValueError","if","called","after","``","prepare","''","."]
code: def add(self, node, *predecessors):
      """Add a new node and its predecessors to the graph.
  
      Both the *node* and all elements in *predecessors* must be hashable.
  
      If called multiple times with the same node argument, the set of dependencies
      will be the union of all dependencies passed in.
  
      It is possible to add a node with no dependencies (*predecessors* is not provided)
      as well as provide a dependency twice. If a node that has not been provided before
      is included among *predecessors* it will be automatically added to the graph with
      no predecessors of its own.
  
      Raises ValueError if called after "prepare".
      """
      if self._ready_nodes is not None:
          raise ValueError(
              "Nodes cannot be added after a call to prepare()"
          )
  
      # Create the node -> predecessor edges
      nodeinfo = self._get_nodeinfo(node)
      nodeinfo.npredecessors += len(predecessors)
  
      # Create the predecessor -> node edges
      for pred in predecessors:
          pred_info = self._get_nodeinfo(pred)
          pred_info.successors.append(node)
  
file_path: cpython/Lib/graphlib.py
imports: from types import GenericAlias
label_desc: Use image node_id 3 for calling the TopologicalSorter obj's underlying member method code with example usage: obj.add(node) without return types