searoute-py icon indicating copy to clipboard operation
searoute-py copied to clipboard

kwargs required in add_edges_from_list

Open IansGithubAcc opened this issue 1 year ago • 1 comments

I'm adding custom rootes to the default MarNet using add_edges_from_list. This function takes an edge_list as input. However, when unpacking the edge it is assuming it has additional args. This is ofc not always the case and in this case you need to add an empty dict.

I suggest to rewrite this:

    def add_edges_from_list(self, edge_list):
        if not edge_list:
            return
        
        for edge in edge_list:
            u,v,args = edge
            self.add_edge(u, v, **args)

to this:

    def add_edges_from_list(self, edge_list):
        if not edge_list:
            return
        
        for edge in edge_list:
            if len(edge) > 2:
                u, v, args = edge
                self.add_edge(u, v, **args)

            else:
                self.add_edge(*edge)

IansGithubAcc avatar Sep 25 '23 12:09 IansGithubAcc