diff --git a/src/sage/graphs/path_enumeration.pyx b/src/sage/graphs/path_enumeration.pyx index f77d1fd239a..28a42b185e9 100644 --- a/src/sage/graphs/path_enumeration.pyx +++ b/src/sage/graphs/path_enumeration.pyx @@ -734,6 +734,12 @@ def yen_k_shortest_simple_paths(self, source, target, weight_function=None, [1, 6, 9, 10, 5], [1, 6, 9, 3, 4, 5], [1, 6, 9, 11, 10, 5]] + + When ``s == t`` and ``report_edge == True`` and ``report_weight == True`` (:issue:`40247`):: + + sage: g = DiGraph([(1, 2)]) + sage: list(yen_k_shortest_simple_paths(g, 1, 1, report_edges=True, report_weight=True)) + [(0, [])] """ if source not in self: raise ValueError("vertex '{}' is not in the graph".format(source)) @@ -741,12 +747,8 @@ def yen_k_shortest_simple_paths(self, source, target, weight_function=None, raise ValueError("vertex '{}' is not in the graph".format(target)) if source == target: - if report_edges: - yield [] - elif report_weight: - yield (0, [source]) - else: - yield [source] + P = [] if report_edges else [source] + yield (0, P) if report_weight else P return if self.has_loops() or self.allows_multiple_edges():