Adds a new neighbor to the node.

        Arguments:
            edge (Edge): The edge that would connect this node with its neighbor.

def add_neighbor(self, edge: "Edge") -> None:
        """
        Adds a new neighbor to the node.

        Arguments:
            edge (Edge): The edge that would connect this node with its neighbor.
        """
        if edge is None or (edge.source != self and edge.target != self):
            return

        if edge.source == self:
            other: Node = edge.target
        elif edge.target == self:
            other: Node = edge.source
        else:
            raise ValueError("Tried to add a neighbor with an invalid edge.")

        edge_key: Tuple(int, int) = edge.key

        # The graph is considered undirected, check neighbor existence accordingly.
        if self._neighbors.get(edge_key) or self._neighbors.get((edge_key[1], edge_key[0])):
            return  # The neighbor is already added.

        self._neighbors[edge_key] = edge
        self.dispatch_event(NeighborAddedEvent(other))