Repository: torressa/cspy (language: python)

Issue:
Cpp Rewrite



Discussion / hints:

Fix patch:
diff --git a/src/python/algorithms/bidirectional.py b/src/python/algorithms/bidirectional.py
index 7a65539..011126c 100644
--- a/src/python/algorithms/bidirectional.py
+++ b/src/python/algorithms/bidirectional.py
@@ -99,11 +99,9 @@ def __init__(self,
             self.bidirectional_cpp.direction = direction
         if method in ["random", "generated", "processed"]:
             self.bidirectional_cpp.method = method
-        if time_limit is not None and (isinstance(time_limit, int) or
-                                       isinstance(time_limit, float)):
+        if time_limit is not None and isinstance(time_limit, (int, float)):
             self.bidirectional_cpp.time_limit = time_limit
-        if threshold is not None and (isinstance(time_limit, int) or
-                                      isinstance(time_limit, float)):
+        if threshold is not None and isinstance(time_limit, (int, float)):
             self.bidirectional_cpp.threshold = threshold
         if isinstance(elementary, bool) and not elementary:
             self.bidirectional_cpp.elementary = elementary
@@ -132,21 +130,21 @@ def path(self):
         """
         path = self.bidirectional_cpp.getPath()
         # format as list on return as SWIG returns "tuple"
-        if len(path) > 0:
-            _path = []
-            # Convert path to its original types and return
-            for p in path:
-                if p == "Source" or p == "Sink":
-                    _path.append(p)
-                else:
-                    if "int" in self._original_node_type.__name__:
-                        _path.append(int(p))
-                    elif "str" in self._original_node_type.__name__:
-                        _path.append(str(p))
-            return _path
-        else:
+        if len(path) <= 0:
             return None
 
+        _path = []
+            # Convert path to its original types and return
+        for p in path:
+            if p in ["Source", "Sink"]:
+                _path.append(p)
+            else:
+                if "int" in self._original_node_type.__name__:
+                    _path.append(int(p))
+                elif "str" in self._original_node_type.__name__:
+                    _path.append(str(p))
+        return _path
+
     @property
     def total_cost(self):
         """Get accumulated cost along the path.
@@ -167,7 +165,9 @@ def consumed_resources(self):
 
     def _init_graph(self, G):
         self._original_node_type = type(
-            [n for n in G.nodes() if n != "Source" and n != "Sink"][0])
+            [n for n in G.nodes() if n not in ["Source", "Sink"]][0]
+        )
+
         for edge in G.edges(data=True):
             res_cost = _convert_list_to_double_vector(edge[2]["res_cost"])
             self.bidirectional_cpp.addEdge(str(edge[0]), str(edge[1]),


Test patch:
diff --git a/test/python/example_ref.py b/test/python/example_ref.py
index 1e1454d..27cb590 100644
--- a/test/python/example_ref.py
+++ b/test/python/example_ref.py
@@ -12,8 +12,7 @@ class Callback(REFCallback):
     def REF_fwd(self, cumul_res, tail, head, edge_res, partial_path,
                 cumul_cost):
         print(cumul_res, tail, head, edge_res, partial_path, cumul_cost)
-        new_res = cumul_res + edge_res
-        return new_res
+        return cumul_res + edge_res
 
 
 def main():