'Appends a new Node to the graph.
An optional base parameter can be used to pass a subclass of Node.'

def add_node(self, id, *args, **kwargs):

    n = kwargs.pop('base', Node)
    n = ((isinstance(id, Node) and id) or self.get(id) or n(id, *args, **kwargs))
    if (n.id not in self):
        self.nodes.append(n)
        self[n.id] = n
        n.graph = self
        self.root = ((kwargs.get('root', False) and n) or self.root)
        self._adjacency = None
    return n
