From 5e79931d4b20c110c5c45ea1939e48aa5c60be2c Mon Sep 17 00:00:00 2001 From: JustineFricou Date: Mon, 13 May 2024 12:30:03 +0200 Subject: [PATCH] Correct returns when no path could be found Methods that return an array when a path is found now return [] instead of None if no path can be found --- geotrek/core/path_router.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/geotrek/core/path_router.py b/geotrek/core/path_router.py index c9261c12ca..8f0f303ba4 100644 --- a/geotrek/core/path_router.py +++ b/geotrek/core/path_router.py @@ -150,7 +150,7 @@ def get_edge_weight(self, edge_id): def get_route(self, steps): self.steps = steps line_strings = self.compute_list_of_paths() - if line_strings is None: + if line_strings == []: return None multi_line_string = GeometryCollection(line_strings, srid=settings.SRID) @@ -166,8 +166,8 @@ def compute_list_of_paths(self): from_step = self.steps[i] to_step = self.steps[i + 1] line_strings = self.compute_two_steps_line_strings(from_step, to_step) - if line_strings is None: - return None + if line_strings == []: + return [] merged_line_string = self.merge_line_strings(line_strings) all_line_strings.append(merged_line_string) return all_line_strings @@ -178,8 +178,8 @@ def compute_two_steps_line_strings(self, from_step, to_step): shortest_path = self.get_shortest_path(from_node_info['node_id'], to_node_info['node_id']) - if shortest_path is None: - return None + if shortest_path == []: + return [] line_strings = self.node_list_to_line_strings(shortest_path, from_node_info, to_node_info) @@ -417,7 +417,7 @@ def get_node_id_per_idx(node_idx): while current_node_id != from_node_id: if current_node_idx < 0: # The path ends here but this node is not the destination - return None + return [] current_node_idx = predecessors[current_node_idx] current_node_id = get_node_id_per_idx(current_node_idx) path.append(current_node_id)