Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ from numpy.random import RandomState
__all__ = ["diameter"]

@_dispatchable
def diameter(G: Graph[_Node], seed: int | RandomState | None = None): ...
def diameter(G: Graph[_Node], seed: int | RandomState | None = None) -> int: ...
4 changes: 2 additions & 2 deletions stubs/networkx/networkx/algorithms/approximation/maxcut.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ __all__ = ["randomized_partitioning", "one_exchange"]
@_dispatchable
def randomized_partitioning(
G: Graph[_Node], seed: int | RandomState | None = None, p: float = 0.5, weight: str | None = None
): ...
) -> tuple[float, tuple[set[Incomplete], set[Incomplete]]]: ...
@_dispatchable
def one_exchange(
G: Graph[_Node], initial_cut: set[Incomplete] | None = None, seed: int | RandomState | None = None, weight: str | None = None
): ...
) -> tuple[float, tuple[set[Incomplete], set[Incomplete]]]: ...
4 changes: 3 additions & 1 deletion stubs/networkx/networkx/algorithms/approximation/ramsey.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from _typeshed import Incomplete

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable

__all__ = ["ramsey_R2"]

@_dispatchable
def ramsey_R2(G: Graph[_Node]): ...
def ramsey_R2(G: Graph[_Node]) -> tuple[set[Incomplete], set[Incomplete]]: ...
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ __all__ = ["metric_closure", "steiner_tree"]
@deprecated(
"`metric_closure` is deprecated and will be removed in NetworkX 3.8. Use `networkx.all_pairs_shortest_path_length` instead."
)
def metric_closure(G: Graph[_Node], weight="weight"): ...
def metric_closure(G: Graph[_Node], weight="weight") -> Graph[Incomplete]: ...
@_dispatchable
def steiner_tree(G: Graph[_Node], terminal_nodes: Iterable[Incomplete], weight: str = "weight", method: str | None = None): ...
def steiner_tree(
G: Graph[_Node], terminal_nodes: Iterable[Incomplete], weight: str = "weight", method: str | None = None
) -> Graph[Incomplete]: ...
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,42 @@ def traveling_salesman_problem(
cycle: bool = True,
method: Callable[..., Incomplete] | None = None,
**kwargs,
): ...
) -> list[Incomplete]: ...
@_dispatchable
def asadpour_atsp(
G: DiGraph[_Node], weight: str | None = "weight", seed: int | RandomState | None = None, source: str | None = None
): ...
) -> list[Incomplete]: ...
@_dispatchable
def held_karp_ascent(G: Graph[_Node], weight="weight"): ...
def held_karp_ascent(
G: Graph[_Node], weight: str = "weight"
) -> tuple[float, dict[Incomplete, Incomplete] | Graph[Incomplete]]: ...
@_dispatchable
def spanning_tree_distribution(G: Graph[_Node], z: Mapping[Incomplete, Incomplete]) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def greedy_tsp(G: Graph[_Node], weight: str | None = "weight", source=None): ...
def greedy_tsp(G: Graph[_Node], weight: str | None = "weight", source=None) -> list[Incomplete]: ...
@_dispatchable
def simulated_annealing_tsp(
G: Graph[_Node],
init_cycle,
init_cycle: Literal["greedy"] | Iterable[Incomplete],
weight: str | None = "weight",
source=None,
temp: int | None = 100,
move="1-1",
move: Callable[..., Incomplete] | Literal["1-1", "1-0"] = "1-1",
max_iterations: int | None = 10,
N_inner: int | None = 100,
alpha=0.01,
alpha: float = 0.01,
seed: int | RandomState | None = None,
): ...
) -> list[Incomplete]: ...
@_dispatchable
def threshold_accepting_tsp(
G: Graph[_Node],
init_cycle: Literal["greedy"] | Iterable[Incomplete],
weight: str | None = "weight",
source=None,
threshold: int | None = 1,
move="1-1",
move: Callable[..., Incomplete] | Literal["1-1", "1-0"] = "1-1",
max_iterations: int | None = 10,
N_inner: int | None = 100,
alpha=0.1,
alpha: float = 0.1,
seed: int | RandomState | None = None,
): ...
) -> list[Incomplete]: ...
7 changes: 4 additions & 3 deletions stubs/networkx/networkx/algorithms/assortativity/mixing.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from _typeshed import Incomplete
from collections.abc import Iterable, Mapping

import numpy as np
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable

Expand All @@ -17,7 +18,7 @@ def attribute_mixing_matrix(
nodes: Iterable[Incomplete] | None = None,
mapping: Mapping[Incomplete, Incomplete] | None = None,
normalized: bool = True,
): ...
) -> np.ndarray[Incomplete, Incomplete]: ...
@_dispatchable
def degree_mixing_dict(
G: Graph[_Node], x: str = "out", y: str = "in", weight: str | None = None, nodes=None, normalized: bool = False
Expand All @@ -31,6 +32,6 @@ def degree_mixing_matrix(
nodes: Iterable[Incomplete] | None = None,
normalized: bool = True,
mapping: Mapping[Incomplete, Incomplete] | None = None,
): ...
) -> np.ndarray[Incomplete, Incomplete]: ...
@_dispatchable
def mixing_dict(xy, normalized: bool = False) -> dict[Incomplete, Incomplete]: ...
def mixing_dict(xy: Iterable[tuple[Incomplete, Incomplete]], normalized: bool = False) -> dict[Incomplete, Incomplete]: ...
6 changes: 3 additions & 3 deletions stubs/networkx/networkx/algorithms/bipartite/basic.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from _typeshed import Incomplete
from collections.abc import Iterable
from collections.abc import Collection, Iterable

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
Expand All @@ -15,6 +15,6 @@ def is_bipartite_node_set(G: Graph[_Node], nodes: Iterable[Incomplete]) -> bool:
@_dispatchable
def sets(G: Graph[_Node], top_nodes: Iterable[Incomplete] | None = None) -> tuple[set[Incomplete], set[Incomplete]]: ...
@_dispatchable
def density(B: Graph[_Node], nodes) -> float: ...
def density(B: Graph[_Node], nodes: Collection[Incomplete]) -> float: ...

@yangdanny97 yangdanny97 Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A representative example:

the docs say "list or container", typed as Collection because the implementation calls len()

https://networkx.org/documentation/stable/_modules/networkx/algorithms/bipartite/basic.html#density

in most cases the "list" params were widened to Iterable unless the implementation calls len(), in which case I widen to Collection

@_dispatchable
def degrees(B: Graph[_Node], nodes, weight: str | None = None) -> tuple[Incomplete, Incomplete]: ...
def degrees(B: Graph[_Node], nodes: Iterable[Incomplete], weight: str | None = None) -> tuple[Incomplete, Incomplete]: ...
9 changes: 6 additions & 3 deletions stubs/networkx/networkx/algorithms/bipartite/centrality.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from _typeshed import Incomplete
from collections.abc import Iterable

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable

__all__ = ["degree_centrality", "betweenness_centrality", "closeness_centrality"]

@_dispatchable
def degree_centrality(G: Graph[_Node], nodes) -> dict[Incomplete, Incomplete]: ...
def degree_centrality(G: Graph[_Node], nodes: Iterable[Incomplete]) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def betweenness_centrality(G: Graph[_Node], nodes) -> dict[Incomplete, Incomplete]: ...
def betweenness_centrality(G: Graph[_Node], nodes: Iterable[Incomplete]) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def closeness_centrality(G: Graph[_Node], nodes, normalized: bool | None = True) -> dict[Incomplete, Incomplete]: ...
def closeness_centrality(
G: Graph[_Node], nodes: Iterable[Incomplete], normalized: bool | None = True
) -> dict[Incomplete, Incomplete]: ...
28 changes: 17 additions & 11 deletions stubs/networkx/networkx/algorithms/bipartite/edgelist.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections.abc import Generator
from _typeshed import Incomplete, StrPath, SupportsRead, SupportsWrite
from collections.abc import Collection, Generator, Iterable

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
Expand All @@ -7,27 +8,32 @@ __all__ = ["generate_edgelist", "write_edgelist", "parse_edgelist", "read_edgeli

@_dispatchable
def write_edgelist(
G: Graph[_Node], path, comments: str = "#", delimiter: str = " ", data: bool = True, encoding: str = "utf-8"
G: Graph[_Node],
path: StrPath | SupportsWrite[bytes],
comments: str = "#",
delimiter: str = " ",
data: bool = True,
encoding: str = "utf-8",
) -> None: ...
@_dispatchable
def generate_edgelist(G: Graph[_Node], delimiter: str = " ", data: bool = True) -> Generator[str]: ...
@_dispatchable
def parse_edgelist(
lines,
lines: Iterable[str],
comments: str | None = "#",
delimiter: str | None = None,
create_using: Graph[_Node] | None = None,
nodetype=None,
data=True,
): ...
create_using: Graph[_Node] | type[Graph[_Node]] | None = None,
nodetype: type[Incomplete] | None = None,
data: bool | Collection[tuple[str, type[Incomplete]]] = True,
) -> Graph[Incomplete]: ...
@_dispatchable
def read_edgelist(
path,
path: StrPath | SupportsRead[bytes],
comments: str | None = "#",
delimiter: str | None = None,
create_using=None,
create_using: Graph[Incomplete] | type[Graph[Incomplete]] | None = None,
nodetype=None,
data=True,
data: bool | Collection[tuple[str, type[Incomplete]]] = True,
edgetype=None,
encoding: str | None = "utf-8",
): ...
) -> Graph[Incomplete]: ...
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ from networkx.utils.backends import _dispatchable
__all__ = ["maximal_extendability"]

@_dispatchable
def maximal_extendability(G: Graph[_Node]): ...
def maximal_extendability(G: Graph[_Node]) -> int: ...
17 changes: 11 additions & 6 deletions stubs/networkx/networkx/algorithms/bipartite/generators.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,32 @@ __all__ = [
]

@_dispatchable
def complete_bipartite_graph(n1, n2, create_using: Graph[_Node] | None = None): ...
def complete_bipartite_graph(n1, n2, create_using: Graph[_Node] | type[Graph[_Node]] | None = None): ...
@_dispatchable
def configuration_model(
aseq: Iterable[Incomplete],
bseq: Iterable[Incomplete],
create_using: Graph[_Node] | None = None,
create_using: Graph[_Node] | type[Graph[_Node]] | None = None,
seed: int | RandomState | None = None,
): ...
@_dispatchable
def havel_hakimi_graph(aseq: Iterable[Incomplete], bseq: Iterable[Incomplete], create_using: Graph[_Node] | None = None): ...
def havel_hakimi_graph(
aseq: Iterable[Incomplete], bseq: Iterable[Incomplete], create_using: Graph[_Node] | type[Graph[_Node]] | None = None
): ...
@_dispatchable
def reverse_havel_hakimi_graph(
aseq: Iterable[Incomplete], bseq: Iterable[Incomplete], create_using: Graph[_Node] | None = None
aseq: Iterable[Incomplete], bseq: Iterable[Incomplete], create_using: Graph[_Node] | type[Graph[_Node]] | None = None
): ...
@_dispatchable
def alternating_havel_hakimi_graph(
aseq: Iterable[Incomplete], bseq: Iterable[Incomplete], create_using: Graph[_Node] | None = None
aseq: Iterable[Incomplete], bseq: Iterable[Incomplete], create_using: Graph[_Node] | type[Graph[_Node]] | None = None
): ...
@_dispatchable
def preferential_attachment_graph(
aseq: Iterable[Incomplete], p: float, create_using: Graph[_Node] | None = None, seed: int | RandomState | None = None
aseq: Iterable[Incomplete],
p: float,
create_using: Graph[_Node] | type[Graph[_Node]] | None = None,
seed: int | RandomState | None = None,
): ...
@_dispatchable
def random_graph(n: int, m: int, p: float, seed: int | RandomState | None = None, directed: bool | None = False): ...
Expand Down
2 changes: 1 addition & 1 deletion stubs/networkx/networkx/algorithms/bipartite/matching.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def eppstein_matching(G: Graph[_Node], top_nodes: Iterable[Incomplete] | None =
@_dispatchable
def to_vertex_cover(
G: Graph[_Node], matching: Mapping[Incomplete, Incomplete], top_nodes: Iterable[Incomplete] | None = None
): ...
) -> set[Incomplete]: ...

maximum_matching = hopcroft_karp_matching

Expand Down
9 changes: 5 additions & 4 deletions stubs/networkx/networkx/algorithms/bipartite/matrix.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from _typeshed import Incomplete
from collections.abc import Iterable

import numpy as np
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable

Expand All @@ -11,16 +12,16 @@ def biadjacency_matrix(
G: Graph[_Node],
row_order: Iterable[_Node],
column_order: Iterable[Incomplete] | None = None,
dtype=None,
dtype: np.dtype[Incomplete] | None = None,
weight: str | None = "weight",
format="csr",
format: str = "csr",
): ... # Return is a complex union of scipy classes depending on the format param
@_dispatchable
def from_biadjacency_matrix(
A,
create_using: Graph[_Node] | None = None,
create_using: Graph[_Node] | type[Graph[_Node]] | None = None,
edge_attribute: str = "weight",
*,
row_order: Iterable[Incomplete] | None = None,
column_order: Iterable[Incomplete] | None = None,
): ...
) -> Graph[Incomplete]: ...
10 changes: 5 additions & 5 deletions stubs/networkx/networkx/algorithms/bipartite/projection.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ __all__ = [
]

@_dispatchable
def projected_graph(B: Graph[_Node], nodes: Iterable[Incomplete], multigraph: bool = False): ...
def projected_graph(B: Graph[_Node], nodes: Iterable[Incomplete], multigraph: bool = False) -> Graph[Incomplete]: ...
@_dispatchable
def weighted_projected_graph(B: Graph[_Node], nodes: Iterable[Incomplete], ratio: bool = False): ...
def weighted_projected_graph(B: Graph[_Node], nodes: Iterable[Incomplete], ratio: bool = False) -> Graph[Incomplete]: ...
@_dispatchable
def collaboration_weighted_projected_graph(B: Graph[_Node], nodes: Iterable[Incomplete]): ...
def collaboration_weighted_projected_graph(B: Graph[_Node], nodes: Iterable[Incomplete]) -> Graph[Incomplete]: ...
@_dispatchable
def overlap_weighted_projected_graph(B: Graph[_Node], nodes: Iterable[Incomplete], jaccard: bool = True): ...
def overlap_weighted_projected_graph(B: Graph[_Node], nodes: Iterable[Incomplete], jaccard: bool = True) -> Graph[Incomplete]: ...
@_dispatchable
def generic_weighted_projected_graph(
B: Graph[_Node], nodes: Iterable[Incomplete], weight_function: Callable[..., Incomplete] | None = None
): ...
) -> Graph[Incomplete]: ...
5 changes: 4 additions & 1 deletion stubs/networkx/networkx/algorithms/bipartite/spectral.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from _typeshed import Incomplete
from collections.abc import Iterable

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable

__all__ = ["spectral_bipartivity"]

@_dispatchable
def spectral_bipartivity(G: Graph[_Node], nodes=None, weight: str = "weight") -> float | dict[Incomplete, Incomplete]: ...
def spectral_bipartivity(
G: Graph[_Node], nodes: Iterable[Incomplete] | None = None, weight: str = "weight"
) -> float | dict[Incomplete, Incomplete]: ...
10 changes: 7 additions & 3 deletions stubs/networkx/networkx/algorithms/centrality/group.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from _typeshed import Incomplete
from collections.abc import Iterable
from collections.abc import Collection, Iterable

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
Expand All @@ -15,8 +15,12 @@ __all__ = [

@_dispatchable
def group_betweenness_centrality(
G: Graph[_Node], C, normalized: bool | None = True, weight: str | None = None, endpoints: bool | None = False
): ...
G: Graph[_Node],
C: Collection[Incomplete],
normalized: bool | None = True,
weight: str | None = None,
endpoints: bool | None = False,
) -> list[float] | float: ...
@_dispatchable
def prominent_group(
G: Graph[_Node],
Expand Down
3 changes: 2 additions & 1 deletion stubs/networkx/networkx/algorithms/centrality/laplacian.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from _typeshed import Incomplete
from collections.abc import Collection

from networkx.classes.graph import Graph, _Node
Expand All @@ -13,4 +14,4 @@ def laplacian_centrality(
weight: str | None = "weight",
walk_type: str | None = None,
alpha: float = 0.95,
): ...
) -> dict[Incomplete, Incomplete]: ...
2 changes: 1 addition & 1 deletion stubs/networkx/networkx/algorithms/centrality/load.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ def newman_betweenness_centrality(
load_centrality = newman_betweenness_centrality

@_dispatchable
def edge_load_centrality(G: Graph[_Node], cutoff: bool | None = False): ...
def edge_load_centrality(G: Graph[_Node], cutoff: bool | None = False) -> dict[tuple[Incomplete, Incomplete], int]: ...
10 changes: 6 additions & 4 deletions stubs/networkx/networkx/algorithms/clique.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ def find_cliques(G: Graph[_Node], nodes: Iterable[Incomplete] | None = None) ->
def find_cliques_recursive(G: Graph[_Node], nodes: Iterable[Incomplete] | None = None) -> Iterator[list[_Node]]: ...
@_dispatchable
def make_max_clique_graph(
G: Graph[_Node], create_using: Graph[_Node, _NodeData, _EdgeData] | None = None
G: Graph[_Node], create_using: Graph[_Node, _NodeData, _EdgeData] | type[Graph[_Node, _NodeData, _EdgeData]] | None = None
) -> Graph[_Node, _NodeData, _EdgeData]: ...
@_dispatchable
def make_clique_bipartite(
G: Graph[_Node, _NodeData, _EdgeData],
fpos: bool | None = None,
create_using: Graph[_Node, _NodeData, _EdgeData] | None = None,
create_using: Graph[_Node, _NodeData, _EdgeData] | type[Graph[_Node, _NodeData, _EdgeData]] | None = None,
name=None,
) -> Graph[_Node]: ...

Expand All @@ -41,9 +41,11 @@ def node_clique_number(
@overload
def node_clique_number(G: Graph[_Node], nodes=None, cliques: Iterable[Incomplete] | None = None, separate_nodes=False) -> int: ...

def number_of_cliques(G: Graph[_Node], nodes=None, cliques=None) -> int | dict[Incomplete, Incomplete]: ...
def number_of_cliques(
G: Graph[_Node], nodes: list[_Node] | _Node | None = None, cliques: Iterable[Incomplete] | None = None
) -> int | dict[Incomplete, Incomplete]: ...
@_dispatchable
def max_weight_clique(G: Graph[_Node], weight="weight") -> tuple[list[Incomplete], int]: ...
def max_weight_clique(G: Graph[_Node], weight: str | None = "weight") -> tuple[list[Incomplete], int]: ...

class MaxWeightClique:
G: Graph[Incomplete]
Expand Down
Loading