summaryrefslogtreecommitdiff
path: root/graph.py
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2009-11-12 11:30:13 +0100
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2009-11-12 11:30:13 +0100
commit1b4d12cbd2ab6e6e586743df592648faa42fa26e (patch)
tree3712c032158bbca5d0f6cb75834c2490271f6698 /graph.py
parent6505d63fb9e53b28ff54b60954f63a9840959905 (diff)
downloadlogilab-common-1b4d12cbd2ab6e6e586743df592648faa42fa26e.tar.gz
fix has_path returned value to include the destination node, else we get
an empty list which makes think there is no path (test added)
Diffstat (limited to 'graph.py')
-rw-r--r--graph.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/graph.py b/graph.py
index c81887e..a6b7900 100644
--- a/graph.py
+++ b/graph.py
@@ -189,16 +189,16 @@ def has_path(graph_dict, fromnode, tonode, path=None):
node has key associated to a list of nodes directly reachable from it.
Return None if no path exists to go from `fromnode` to `tonode`, else the
- first path found
+ first path found (as a list including the destination node at last)
"""
if path is None:
path = []
elif fromnode in path:
- return False
+ return None
path.append(fromnode)
for destnode in graph_dict[fromnode]:
if destnode == tonode or has_path(graph_dict, destnode, tonode, path):
- return path[1:]
+ return path[1:] + [tonode]
path.pop()
return None