Skip to content

Commit a6af071

Browse files
authored
[networkx] Improve type coverage (#16028)
1 parent 0ff2bb2 commit a6af071

125 files changed

Lines changed: 981 additions & 462 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

stubs/networkx/networkx/algorithms/approximation/distance_measures.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ from numpy.random import RandomState
55
__all__ = ["diameter"]
66

77
@_dispatchable
8-
def diameter(G: Graph[_Node], seed: int | RandomState | None = None): ...
8+
def diameter(G: Graph[_Node], seed: int | RandomState | None = None) -> int: ...

stubs/networkx/networkx/algorithms/approximation/maxcut.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ __all__ = ["randomized_partitioning", "one_exchange"]
99
@_dispatchable
1010
def randomized_partitioning(
1111
G: Graph[_Node], seed: int | RandomState | None = None, p: float = 0.5, weight: str | None = None
12-
): ...
12+
) -> tuple[float, tuple[set[Incomplete], set[Incomplete]]]: ...
1313
@_dispatchable
1414
def one_exchange(
1515
G: Graph[_Node], initial_cut: set[Incomplete] | None = None, seed: int | RandomState | None = None, weight: str | None = None
16-
): ...
16+
) -> tuple[float, tuple[set[Incomplete], set[Incomplete]]]: ...
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
from _typeshed import Incomplete
2+
13
from networkx.classes.graph import Graph, _Node
24
from networkx.utils.backends import _dispatchable
35

46
__all__ = ["ramsey_R2"]
57

68
@_dispatchable
7-
def ramsey_R2(G: Graph[_Node]): ...
9+
def ramsey_R2(G: Graph[_Node]) -> tuple[set[Incomplete], set[Incomplete]]: ...

stubs/networkx/networkx/algorithms/approximation/steinertree.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ __all__ = ["metric_closure", "steiner_tree"]
1111
@deprecated(
1212
"`metric_closure` is deprecated and will be removed in NetworkX 3.8. Use `networkx.all_pairs_shortest_path_length` instead."
1313
)
14-
def metric_closure(G: Graph[_Node], weight="weight"): ...
14+
def metric_closure(G: Graph[_Node], weight="weight") -> Graph[Incomplete]: ...
1515
@_dispatchable
16-
def steiner_tree(G: Graph[_Node], terminal_nodes: Iterable[Incomplete], weight: str = "weight", method: str | None = None): ...
16+
def steiner_tree(
17+
G: Graph[_Node], terminal_nodes: Iterable[Incomplete], weight: str = "weight", method: str | None = None
18+
) -> Graph[Incomplete]: ...

stubs/networkx/networkx/algorithms/approximation/traveling_salesman.pyi

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,42 @@ def traveling_salesman_problem(
3030
cycle: bool = True,
3131
method: Callable[..., Incomplete] | None = None,
3232
**kwargs,
33-
): ...
33+
) -> list[Incomplete]: ...
3434
@_dispatchable
3535
def asadpour_atsp(
3636
G: DiGraph[_Node], weight: str | None = "weight", seed: int | RandomState | None = None, source: str | None = None
37-
): ...
37+
) -> list[Incomplete]: ...
3838
@_dispatchable
39-
def held_karp_ascent(G: Graph[_Node], weight="weight"): ...
39+
def held_karp_ascent(
40+
G: Graph[_Node], weight: str = "weight"
41+
) -> tuple[float, dict[Incomplete, Incomplete] | Graph[Incomplete]]: ...
4042
@_dispatchable
4143
def spanning_tree_distribution(G: Graph[_Node], z: Mapping[Incomplete, Incomplete]) -> dict[Incomplete, Incomplete]: ...
4244
@_dispatchable
43-
def greedy_tsp(G: Graph[_Node], weight: str | None = "weight", source=None): ...
45+
def greedy_tsp(G: Graph[_Node], weight: str | None = "weight", source=None) -> list[Incomplete]: ...
4446
@_dispatchable
4547
def simulated_annealing_tsp(
4648
G: Graph[_Node],
47-
init_cycle,
49+
init_cycle: Literal["greedy"] | Iterable[Incomplete],
4850
weight: str | None = "weight",
4951
source=None,
5052
temp: int | None = 100,
51-
move="1-1",
53+
move: Callable[..., Incomplete] | Literal["1-1", "1-0"] = "1-1",
5254
max_iterations: int | None = 10,
5355
N_inner: int | None = 100,
54-
alpha=0.01,
56+
alpha: float = 0.01,
5557
seed: int | RandomState | None = None,
56-
): ...
58+
) -> list[Incomplete]: ...
5759
@_dispatchable
5860
def threshold_accepting_tsp(
5961
G: Graph[_Node],
6062
init_cycle: Literal["greedy"] | Iterable[Incomplete],
6163
weight: str | None = "weight",
6264
source=None,
6365
threshold: int | None = 1,
64-
move="1-1",
66+
move: Callable[..., Incomplete] | Literal["1-1", "1-0"] = "1-1",
6567
max_iterations: int | None = 10,
6668
N_inner: int | None = 100,
67-
alpha=0.1,
69+
alpha: float = 0.1,
6870
seed: int | RandomState | None = None,
69-
): ...
71+
) -> list[Incomplete]: ...

stubs/networkx/networkx/algorithms/assortativity/mixing.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from _typeshed import Incomplete
22
from collections.abc import Iterable, Mapping
33

4+
import numpy as np
45
from networkx.classes.graph import Graph, _Node
56
from networkx.utils.backends import _dispatchable
67

@@ -17,7 +18,7 @@ def attribute_mixing_matrix(
1718
nodes: Iterable[Incomplete] | None = None,
1819
mapping: Mapping[Incomplete, Incomplete] | None = None,
1920
normalized: bool = True,
20-
): ...
21+
) -> np.ndarray[Incomplete, Incomplete]: ...
2122
@_dispatchable
2223
def degree_mixing_dict(
2324
G: Graph[_Node], x: str = "out", y: str = "in", weight: str | None = None, nodes=None, normalized: bool = False
@@ -31,6 +32,6 @@ def degree_mixing_matrix(
3132
nodes: Iterable[Incomplete] | None = None,
3233
normalized: bool = True,
3334
mapping: Mapping[Incomplete, Incomplete] | None = None,
34-
): ...
35+
) -> np.ndarray[Incomplete, Incomplete]: ...
3536
@_dispatchable
36-
def mixing_dict(xy, normalized: bool = False) -> dict[Incomplete, Incomplete]: ...
37+
def mixing_dict(xy: Iterable[tuple[Incomplete, Incomplete]], normalized: bool = False) -> dict[Incomplete, Incomplete]: ...

stubs/networkx/networkx/algorithms/bipartite/basic.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from _typeshed import Incomplete
2-
from collections.abc import Iterable
2+
from collections.abc import Collection, Iterable
33

44
from networkx.classes.graph import Graph, _Node
55
from networkx.utils.backends import _dispatchable
@@ -15,6 +15,6 @@ def is_bipartite_node_set(G: Graph[_Node], nodes: Iterable[Incomplete]) -> bool:
1515
@_dispatchable
1616
def sets(G: Graph[_Node], top_nodes: Iterable[Incomplete] | None = None) -> tuple[set[Incomplete], set[Incomplete]]: ...
1717
@_dispatchable
18-
def density(B: Graph[_Node], nodes) -> float: ...
18+
def density(B: Graph[_Node], nodes: Collection[Incomplete]) -> float: ...
1919
@_dispatchable
20-
def degrees(B: Graph[_Node], nodes, weight: str | None = None) -> tuple[Incomplete, Incomplete]: ...
20+
def degrees(B: Graph[_Node], nodes: Iterable[Incomplete], weight: str | None = None) -> tuple[Incomplete, Incomplete]: ...
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
from _typeshed import Incomplete
2+
from collections.abc import Iterable
23

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

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

89
@_dispatchable
9-
def degree_centrality(G: Graph[_Node], nodes) -> dict[Incomplete, Incomplete]: ...
10+
def degree_centrality(G: Graph[_Node], nodes: Iterable[Incomplete]) -> dict[Incomplete, Incomplete]: ...
1011
@_dispatchable
11-
def betweenness_centrality(G: Graph[_Node], nodes) -> dict[Incomplete, Incomplete]: ...
12+
def betweenness_centrality(G: Graph[_Node], nodes: Iterable[Incomplete]) -> dict[Incomplete, Incomplete]: ...
1213
@_dispatchable
13-
def closeness_centrality(G: Graph[_Node], nodes, normalized: bool | None = True) -> dict[Incomplete, Incomplete]: ...
14+
def closeness_centrality(
15+
G: Graph[_Node], nodes: Iterable[Incomplete], normalized: bool | None = True
16+
) -> dict[Incomplete, Incomplete]: ...
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from collections.abc import Generator
1+
from _typeshed import Incomplete, StrPath, SupportsRead, SupportsWrite
2+
from collections.abc import Collection, Generator, Iterable
23

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

89
@_dispatchable
910
def write_edgelist(
10-
G: Graph[_Node], path, comments: str = "#", delimiter: str = " ", data: bool = True, encoding: str = "utf-8"
11+
G: Graph[_Node],
12+
path: StrPath | SupportsWrite[bytes],
13+
comments: str = "#",
14+
delimiter: str = " ",
15+
data: bool = True,
16+
encoding: str = "utf-8",
1117
) -> None: ...
1218
@_dispatchable
1319
def generate_edgelist(G: Graph[_Node], delimiter: str = " ", data: bool = True) -> Generator[str]: ...
1420
@_dispatchable
1521
def parse_edgelist(
16-
lines,
22+
lines: Iterable[str],
1723
comments: str | None = "#",
1824
delimiter: str | None = None,
19-
create_using: Graph[_Node] | None = None,
20-
nodetype=None,
21-
data=True,
22-
): ...
25+
create_using: Graph[_Node] | type[Graph[_Node]] | None = None,
26+
nodetype: type[Incomplete] | None = None,
27+
data: bool | Collection[tuple[str, type[Incomplete]]] = True,
28+
) -> Graph[Incomplete]: ...
2329
@_dispatchable
2430
def read_edgelist(
25-
path,
31+
path: StrPath | SupportsRead[bytes],
2632
comments: str | None = "#",
2733
delimiter: str | None = None,
28-
create_using=None,
34+
create_using: Graph[Incomplete] | type[Graph[Incomplete]] | None = None,
2935
nodetype=None,
30-
data=True,
36+
data: bool | Collection[tuple[str, type[Incomplete]]] = True,
3137
edgetype=None,
3238
encoding: str | None = "utf-8",
33-
): ...
39+
) -> Graph[Incomplete]: ...

stubs/networkx/networkx/algorithms/bipartite/extendability.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ from networkx.utils.backends import _dispatchable
44
__all__ = ["maximal_extendability"]
55

66
@_dispatchable
7-
def maximal_extendability(G: Graph[_Node]): ...
7+
def maximal_extendability(G: Graph[_Node]) -> int: ...

0 commit comments

Comments
 (0)