def get_conversion_path(self, start_type, target_type):
start_type = self._normalise_type(start_type)
target_type = self._normalise_type(target_type)
try:
# Retrieve node sequence that leads from start_type to target_type.
path = networkx.shortest_path(self.conversion_graph, start_type, target_type)
# Look up edges between nodes and retrieve the conversion function for each edge.
return [self.conversion_graph.get_edge_data(node_a, node_b)['conversion_function'] for node_a, node_b in
zip(path[:-1], path[1:])]
except networkx.NetworkXNoPath:
raise UndefinedConversionError(
start_type,
target_type,
)
评论列表
文章目录