Repository: networkx/networkx

Issue:
Inconsistent `shortest_path` warning and return type on main


### Current Behavior

#7161 updated the warning for `shortest_path` to indicate the return type (from dict to iterator) will occur in NetworkX 3.5.

#6584 changed the return type from dict to iterator, but #7161 didn't change the return type back to dict.

### Expected Behavior

I expect `shortest_path` with no source or target to return an iterator over node, path pairs on main branch to be consistent with the warning.

### Steps to Reproduce

```
>>> import networkx as nx
>>> assert isinstance(nx.shortest_path(nx.complete_graph(4)), dict)  # raises AssertionError
```

### Environment

Python version: 3.10
NetworkX version: main branch

### Additional context

This is similar to issue #7315. I haven't fully compared #6584, #7161, and main branch to ensure consistency.


Discussion:

Resolving patch:
diff --git a/networkx/algorithms/centrality/reaching.py b/networkx/algorithms/centrality/reaching.py
--- a/networkx/algorithms/centrality/reaching.py
+++ b/networkx/algorithms/centrality/reaching.py
@@ -112,7 +112,7 @@ def as_distance(u, v, d):
     # TODO This can be trivially parallelized.
     lrc = [
         centrality(G, node, paths=paths, weight=weight, normalized=normalized)
-        for node, paths in shortest_paths
+        for node, paths in shortest_paths.items()
     ]
 
     max_lrc = max(lrc)
diff --git a/networkx/algorithms/shortest_paths/generic.py b/networkx/algorithms/shortest_paths/generic.py
--- a/networkx/algorithms/shortest_paths/generic.py
+++ b/networkx/algorithms/shortest_paths/generic.py
@@ -149,11 +149,11 @@ def shortest_path(G, source=None, target=None, weight=None, method="dijkstra"):
 
             # Find paths between all pairs.
             if method == "unweighted":
-                paths = nx.all_pairs_shortest_path(G)
+                paths = dict(nx.all_pairs_shortest_path(G))
             elif method == "dijkstra":
-                paths = nx.all_pairs_dijkstra_path(G, weight=weight)
+                paths = dict(nx.all_pairs_dijkstra_path(G, weight=weight))
             else:  # method == 'bellman-ford':
-                paths = nx.all_pairs_bellman_ford_path(G, weight=weight)
+                paths = dict(nx.all_pairs_bellman_ford_path(G, weight=weight))
         else:
             # Find paths from all nodes co-accessible to the target.
             if G.is_directed():


Test patch:
diff --git a/networkx/algorithms/shortest_paths/tests/test_generic.py b/networkx/algorithms/shortest_paths/tests/test_generic.py
--- a/networkx/algorithms/shortest_paths/tests/test_generic.py
+++ b/networkx/algorithms/shortest_paths/tests/test_generic.py
@@ -212,7 +212,9 @@ def test_single_source_all_shortest_paths(self):
         assert sorted(ans[4]) == [[4]]
 
     def test_all_pairs_shortest_path(self):
-        p = dict(nx.shortest_path(self.cycle))
+        # shortest_path w/o source and target will return a generator instead of
+        # a dict beginning in version 3.5. Only the first call needs changed here.
+        p = nx.shortest_path(self.cycle)
         assert p[0][3] == [0, 1, 2, 3]
         assert p == dict(nx.all_pairs_shortest_path(self.cycle))
         p = dict(nx.shortest_path(self.grid))