Skip to content

Commit 0d47c19

Browse files
committed
widen some input types based on the implementation
1 parent dbf0535 commit 0d47c19

50 files changed

Lines changed: 308 additions & 189 deletions

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/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-
) -> float: ...
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-
) -> float: ...
16+
) -> tuple[float, tuple[set[Incomplete], set[Incomplete]]]: ...

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@ def asadpour_atsp(
3636
G: DiGraph[_Node], weight: str | None = "weight", seed: int | RandomState | None = None, source: str | None = None
3737
) -> list[Incomplete]: ...
3838
@_dispatchable
39-
def held_karp_ascent(G: Graph[_Node], weight: str = "weight") -> float: ...
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
4345
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: list[Incomplete],
49+
init_cycle: Literal["greedy"] | Iterable[Incomplete],
4850
weight: str | None = "weight",
4951
source=None,
5052
temp: int | None = 100,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ def degree_mixing_matrix(
3434
mapping: Mapping[Incomplete, Incomplete] | None = None,
3535
) -> np.ndarray[Incomplete, Incomplete]: ...
3636
@_dispatchable
37-
def mixing_dict(xy: list[Incomplete], 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: list[Incomplete]) -> float: ...
18+
def density(B: Graph[_Node], nodes: Collection[Incomplete]) -> float: ...
1919
@_dispatchable
20-
def degrees(B: Graph[_Node], nodes: list[Incomplete], 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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +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: list[Incomplete]) -> 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: list[Incomplete]) -> dict[Incomplete, Incomplete]: ...
12+
def betweenness_centrality(G: Graph[_Node], nodes: Iterable[Incomplete]) -> dict[Incomplete, Incomplete]: ...
1213
@_dispatchable
1314
def closeness_centrality(
14-
G: Graph[_Node], nodes: list[Incomplete], normalized: bool | None = True
15+
G: Graph[_Node], nodes: Iterable[Incomplete], normalized: bool | None = True
1516
) -> dict[Incomplete, Incomplete]: ...
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from _typeshed import Incomplete
2-
from collections.abc import Generator
1+
from _typeshed import Incomplete, StrPath, SupportsRead, SupportsWrite
2+
from collections.abc import Collection, Generator, Iterable
33

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

99
@_dispatchable
1010
def write_edgelist(
11-
G: Graph[_Node], path: str, 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",
1217
) -> None: ...
1318
@_dispatchable
1419
def generate_edgelist(G: Graph[_Node], delimiter: str = " ", data: bool = True) -> Generator[str]: ...
1520
@_dispatchable
1621
def parse_edgelist(
17-
lines: list[Incomplete],
22+
lines: Iterable[str],
1823
comments: str | None = "#",
1924
delimiter: str | None = None,
20-
create_using: Graph[_Node] | None = None,
25+
create_using: Graph[_Node] | type[Graph[_Node]] | None = None,
2126
nodetype: type[Incomplete] | None = None,
22-
data: bool | list[tuple[Incomplete, type[Incomplete]]] = True,
27+
data: bool | Collection[tuple[str, type[Incomplete]]] = True,
2328
) -> Graph[Incomplete]: ...
2429
@_dispatchable
2530
def read_edgelist(
26-
path: str,
31+
path: StrPath | SupportsRead[bytes],
2732
comments: str | None = "#",
2833
delimiter: str | None = None,
29-
create_using: Graph[Incomplete] | None = None,
34+
create_using: Graph[Incomplete] | type[Graph[Incomplete]] | None = None,
3035
nodetype=None,
31-
data: bool | list[tuple[Incomplete, type[Incomplete]]] = True,
36+
data: bool | Collection[tuple[str, type[Incomplete]]] = True,
3237
edgetype=None,
3338
encoding: str | None = "utf-8",
3439
) -> Graph[Incomplete]: ...

stubs/networkx/networkx/algorithms/bipartite/generators.pyi

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,32 @@ __all__ = [
1717
]
1818

1919
@_dispatchable
20-
def complete_bipartite_graph(n1, n2, create_using: Graph[_Node] | None = None): ...
20+
def complete_bipartite_graph(n1, n2, create_using: Graph[_Node] | type[Graph[_Node]] | None = None): ...
2121
@_dispatchable
2222
def configuration_model(
2323
aseq: Iterable[Incomplete],
2424
bseq: Iterable[Incomplete],
25-
create_using: Graph[_Node] | None = None,
25+
create_using: Graph[_Node] | type[Graph[_Node]] | None = None,
2626
seed: int | RandomState | None = None,
2727
): ...
2828
@_dispatchable
29-
def havel_hakimi_graph(aseq: Iterable[Incomplete], bseq: Iterable[Incomplete], create_using: Graph[_Node] | None = None): ...
29+
def havel_hakimi_graph(
30+
aseq: Iterable[Incomplete], bseq: Iterable[Incomplete], create_using: Graph[_Node] | type[Graph[_Node]] | None = None
31+
): ...
3032
@_dispatchable
3133
def reverse_havel_hakimi_graph(
32-
aseq: Iterable[Incomplete], bseq: Iterable[Incomplete], create_using: Graph[_Node] | None = None
34+
aseq: Iterable[Incomplete], bseq: Iterable[Incomplete], create_using: Graph[_Node] | type[Graph[_Node]] | None = None
3335
): ...
3436
@_dispatchable
3537
def alternating_havel_hakimi_graph(
36-
aseq: Iterable[Incomplete], bseq: Iterable[Incomplete], create_using: Graph[_Node] | None = None
38+
aseq: Iterable[Incomplete], bseq: Iterable[Incomplete], create_using: Graph[_Node] | type[Graph[_Node]] | None = None
3739
): ...
3840
@_dispatchable
3941
def preferential_attachment_graph(
40-
aseq: Iterable[Incomplete], p: float, create_using: Graph[_Node] | None = None, seed: int | RandomState | None = None
42+
aseq: Iterable[Incomplete],
43+
p: float,
44+
create_using: Graph[_Node] | type[Graph[_Node]] | None = None,
45+
seed: int | RandomState | None = None,
4146
): ...
4247
@_dispatchable
4348
def random_graph(n: int, m: int, p: float, seed: int | RandomState | None = None, directed: bool | None = False): ...

stubs/networkx/networkx/algorithms/bipartite/matrix.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def biadjacency_matrix(
1919
@_dispatchable
2020
def from_biadjacency_matrix(
2121
A,
22-
create_using: Graph[_Node] | None = None,
22+
create_using: Graph[_Node] | type[Graph[_Node]] | None = None,
2323
edge_attribute: str = "weight",
2424
*,
2525
row_order: Iterable[Incomplete] | None = None,
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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
@@ -7,5 +8,5 @@ __all__ = ["spectral_bipartivity"]
78

89
@_dispatchable
910
def spectral_bipartivity(
10-
G: Graph[_Node], nodes: list[Incomplete] | None = None, weight: str = "weight"
11+
G: Graph[_Node], nodes: Iterable[Incomplete] | None = None, weight: str = "weight"
1112
) -> float | dict[Incomplete, Incomplete]: ...

stubs/networkx/networkx/algorithms/centrality/group.pyi

Lines changed: 6 additions & 2 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,7 +15,11 @@ __all__ = [
1515

1616
@_dispatchable
1717
def group_betweenness_centrality(
18-
G: Graph[_Node], C: set[Incomplete], normalized: bool | None = True, weight: str | None = None, endpoints: bool | None = False
18+
G: Graph[_Node],
19+
C: Collection[Incomplete],
20+
normalized: bool | None = True,
21+
weight: str | None = None,
22+
endpoints: bool | None = False,
1923
) -> list[float] | float: ...
2024
@_dispatchable
2125
def prominent_group(

0 commit comments

Comments
 (0)