pombreda / pydot

Automatically exported from code.google.com/p/pydot
MIT License
0 stars 0 forks source link

Graph.get_edge() has several bugs... more below #18

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1: When adding an edge to a Graph via add_edge(Edge('foo', 'bar')) the key
value that ends up in the obj_dict['edges'] dictionary is not the ('foo',
'bar') pair, but rather the following: ('"foo"', '"bar"')

This causes me to have to do something silly when using the get_edge
function such as: Graph.get_edge('"%s"'%src, '"%s"'%dst) in order for it to
create ('"foo"', '"bar"') internally and actually find the edge i'm looking
for.

2: The documentation for get_edge() in incorrect.  It states:
"""Retrieved an edge from the graph.

        Given an edge's source and destination the corresponding
        Edge instance will be returned.

        If multiple edges exist with that source and destination,
        a list of Edge instances is returned.
        If only one edge exists, the instance is returned.
        None is returned otherwise.
        """

However in the code there is no place where None is actually returned:
snippet:
        if len(match)==1:
            return match[0]

        return match
should be:
        if len(match)==0:
            return None
        elif len(match)==1:
            return match[0]

        return match

3:  It would be nice if get_edge always returned an Edge or always returned
a list of Edges, but by being able to return both it requires users code to
check what it actually got in return.  If you simply returned a list of
Edges then it is easy for the user to check for None or len() of 1

Original issue reported on code.google.com by VirtualT...@gmail.com on 24 Dec 2008 at 4:49

GoogleCodeExporter commented 9 years ago
This has been dogging me for days, your solution fixed my problem.

Original comment by swn...@gmail.com on 18 Jun 2010 at 11:52

GoogleCodeExporter commented 9 years ago
Indeed, all of them are really annoying.

Original comment by alexander.heinlein@web.de on 8 Sep 2010 at 2:38

GoogleCodeExporter commented 9 years ago

Original comment by ero.carr...@gmail.com on 30 Oct 2010 at 11:05

GoogleCodeExporter commented 9 years ago

Original comment by ero.carr...@gmail.com on 31 Oct 2010 at 12:21

GoogleCodeExporter commented 9 years ago
I agree this behavior is confusing. The new version will return always a list 
for get_node(), get_edges() and get_subgraph()

Original comment by ero.carr...@gmail.com on 1 Nov 2010 at 5:12