Repository: networkx/networkx
Pull request: Fixed the return type from an empty dict to an empty set
Addressing issues #7909 

This PR involves the suggested changes : 
1. fix the typo {} -> set()
2. Adding documentation text under the Returns section about when an empty set is returned.

Additional Changes : 
1. Fix test assertion `tests_minimum_st_node_cut()` by using set() instead of {} for empty set comparison.



Problem statement:
minimum_st_node_cut returns empty dict instead of empty set
### Current Behavior

If you use the method "minimum_st_node_cut" from connectivity with nodes s and t which are directly connected by an edge, the method returns an empty dictionary instead of an empty set.

This is due to the following code part:
```
    if G.has_edge(s, t) or G.has_edge(t, s):
        return {}
```

### Expected Behavior

The method minimum_st_node_cut declares to return a set of nodes. 
So I would expect to get a set in this case, too, not a dict.

```
    Returns
    -------
    cutset : set
        Set of nodes that, if removed, would destroy all paths between
        source and target in G.
```

Probably just a typo: To create an empty set, you would have to use set(), not {} .
So the fix should be:

```
    if G.has_edge(s, t) or G.has_edge(t, s):
        return set()
```

### Steps to Reproduce

```
G = nx.Graph()
G.add_nodes_from(["s", "t"])
G.add_edges_from([("s", "t")])
separator = nx.algorithms.connectivity.minimum_st_node_cut(G, "s", "t")
print (type(separator))
```

### Environment

Python version: 3.13.1
NetworkX version: 3.4.2

### Additional context

It may be unexpected to some users to get an empty nodeset if s and t are directly connected by an edge, even if it is described e.g. in Diestel "Graph Theory", 6. ed., Springer 2025, on page 11 that a nodesset is a separator for vertices a and b if it separates those two vertices and doesn't include a and b. So maybe a hint in the documentation that you should check for an edge between s and t before calling this method would be helpful. Or the documentation for this method could include the information that two totally unconnected nodes s and t and two directly connected nodes s and t with an edge "st" or "ts" will both result in an empty set as return value.

Hints from issue discussion:
I am in favor of both these suggestions:
1) fix the typo `{}` -> `set()`
2) add documentation text (maybe in "Notes" section) about when an empty set is returned.

Thanks!

Commit message: Fixed trailing whitespaces

Patch to review:
diff --git a/networkx/algorithms/connectivity/cuts.py b/networkx/algorithms/connectivity/cuts.py
index 27124e1bdd6..7a1c85c1376 100644
--- a/networkx/algorithms/connectivity/cuts.py
+++ b/networkx/algorithms/connectivity/cuts.py
@@ -207,6 +207,9 @@ def minimum_st_node_cut(G, s, t, flow_func=None, auxiliary=None, residual=None):
         Set of nodes that, if removed, would destroy all paths between
         source and target in G.
 
+        Returns an empty set if source and target are directly connected
+        by an edge in G, as no nodes can destroy their path.
+
     Examples
     --------
     This function is not imported in the base NetworkX namespace, so you
@@ -291,7 +294,7 @@ def minimum_st_node_cut(G, s, t, flow_func=None, auxiliary=None, residual=None):
     if mapping is None:
         raise nx.NetworkXError("Invalid auxiliary digraph.")
     if G.has_edge(s, t) or G.has_edge(t, s):
-        return {}
+        return set()
     kwargs = {"flow_func": flow_func, "residual": residual, "auxiliary": H}
 
     # The edge cut in the auxiliary digraph corresponds to the node cut in the
diff --git a/networkx/algorithms/connectivity/tests/test_cuts.py b/networkx/algorithms/connectivity/tests/test_cuts.py
index 7a485be399d..964aff9c563 100644
--- a/networkx/algorithms/connectivity/tests/test_cuts.py
+++ b/networkx/algorithms/connectivity/tests/test_cuts.py
@@ -289,7 +289,7 @@ def tests_minimum_st_node_cut():
     G.add_nodes_from([0, 1, 2, 3, 7, 8, 11, 12])
     G.add_edges_from([(7, 11), (1, 11), (1, 12), (12, 8), (0, 1)])
     nodelist = minimum_st_node_cut(G, 7, 11)
-    assert nodelist == {}
+    assert nodelist == set()
 
 
 def test_invalid_auxiliary():


Code review comments:
diff_hunk: @@ -207,6 +207,9 @@ def minimum_st_node_cut(G, s, t, flow_func=None, auxiliary=None, residual=None):
         Set of nodes that, if removed, would destroy all paths between
         source and target in G.
 
+        Returns an empty set if source and target are directly connected
+        by an edge in G, as no nodes can destroy their path.
path: networkx/algorithms/connectivity/cuts.py
text: @user1:
```suggestion
        Returns an empty set if source and target are either in different components
        or are directly connected by an edge, as no node removal can destroy the path.
```