Skip to content

Commit 855999e

Browse files
authored
networkx: Add symbols from python-type-stubs (#14084)
1 parent 9dd48ae commit 855999e

38 files changed

+239
-35
lines changed

stubs/networkx/@tests/stubtest_allowlist.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,4 @@ networkx(\.algorithms)?(\.tree)?(\.mst)?\.SpanningTreeIterator\.Partition\._DT
4040
networkx(\.algorithms)?(\.tree)?(\.branchings)?\.ArborescenceIterator\.Partition\._DT
4141

4242
# variable differs from runtime type abc.ABCMeta
43-
networkx.classes.reportviews.EdgeView.dataview
44-
networkx.classes.reportviews.InEdgeView.dataview
45-
networkx.classes.reportviews.OutEdgeView.dataview
46-
networkx.classes.reportviews.OutMultiEdgeView.dataview
43+
networkx\.classes\.reportviews\.\w*EdgeView\.dataview

stubs/networkx/networkx/__init__.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Final
2+
13
from networkx.algorithms import *
24
from networkx.classes import *
35
from networkx.classes import filters as filters
@@ -24,3 +26,5 @@ from . import (
2426
relabel as relabel,
2527
utils as utils,
2628
)
29+
30+
__version__: Final[str]

stubs/networkx/networkx/algorithms/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ from networkx.algorithms.structuralholes import *
118118
from networkx.algorithms.summarization import *
119119
from networkx.algorithms.swap import *
120120
from networkx.algorithms.time_dependent import *
121+
from networkx.algorithms.tournament import is_tournament as is_tournament
121122
from networkx.algorithms.traversal import *
122123
from networkx.algorithms.tree.branchings import (
123124
ArborescenceIterator as ArborescenceIterator,

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from _typeshed import Incomplete
2-
from collections.abc import Callable
1+
from _typeshed import Incomplete, SupportsLenAndGetItem
2+
from collections.abc import Callable, Mapping
3+
from typing import Any, TypeVar
34

45
from networkx.classes.digraph import DiGraph
56
from networkx.classes.graph import Graph, _Node
@@ -15,6 +16,10 @@ __all__ = [
1516
"threshold_accepting_tsp",
1617
]
1718

19+
_SupportsLenAndGetItemT = TypeVar("_SupportsLenAndGetItemT", bound=SupportsLenAndGetItem[Any])
20+
21+
def swap_two_nodes(soln: _SupportsLenAndGetItemT, seed) -> _SupportsLenAndGetItemT: ...
22+
def move_one_node(soln: _SupportsLenAndGetItemT, seed) -> _SupportsLenAndGetItemT: ...
1823
@_dispatchable
1924
def christofides(G: Graph[_Node], weight: str | None = "weight", tree: Graph[_Node] | None = None): ...
2025
@_dispatchable
@@ -31,6 +36,10 @@ def asadpour_atsp(
3136
G: DiGraph[_Node], weight: str | None = "weight", seed: int | RandomState | None = None, source: str | None = None
3237
): ...
3338
@_dispatchable
39+
def held_karp_ascent(G: Graph[_Node], weight="weight"): ...
40+
@_dispatchable
41+
def spanning_tree_distribution(G: Graph[_Node], z: Mapping[Incomplete, Incomplete]) -> dict[Incomplete, Incomplete]: ...
42+
@_dispatchable
3443
def greedy_tsp(G: Graph[_Node], weight: str | None = "weight", source=None): ...
3544
@_dispatchable
3645
def simulated_annealing_tsp(

stubs/networkx/networkx/algorithms/approximation/treewidth.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ class MinDegreeHeuristic:
1515

1616
def __init__(self, graph) -> None: ...
1717
def best_node(self, graph): ...
18+
19+
def min_fill_in_heuristic(graph) -> Incomplete | None: ...
20+
@_dispatchable
21+
def treewidth_decomp(G: Graph[_Node], heuristic=...) -> tuple[int, Graph[_Node]]: ...

stubs/networkx/networkx/algorithms/asteroidal.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from _typeshed import Incomplete
2+
13
from networkx.classes.graph import Graph, _Node
24
from networkx.utils.backends import _dispatchable
35

@@ -7,3 +9,5 @@ __all__ = ["is_at_free", "find_asteroidal_triple"]
79
def find_asteroidal_triple(G: Graph[_Node]): ...
810
@_dispatchable
911
def is_at_free(G: Graph[_Node]) -> bool: ...
12+
@_dispatchable
13+
def create_component_structure(G: Graph[_Node]) -> dict[Incomplete, Incomplete]: ...

stubs/networkx/networkx/algorithms/bipartite/cluster.pyi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
from _typeshed import Incomplete
2-
from collections.abc import Iterable
2+
from collections.abc import Callable, Iterable
33

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

77
__all__ = ["clustering", "average_clustering", "latapy_clustering", "robins_alexander_clustering"]
88

9+
def cc_dot(nu, nv) -> float: ...
10+
def cc_max(nu, nv) -> float: ...
11+
def cc_min(nu, nv) -> float: ...
12+
13+
modes: dict[str, Callable[[Incomplete, Incomplete], float]]
14+
915
@_dispatchable
1016
def latapy_clustering(G: Graph[_Node], nodes: Iterable[Incomplete] | None = None, mode: str = "dot"): ...
1117

stubs/networkx/networkx/algorithms/clique.pyi

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,15 @@ def node_clique_number(G: Graph[_Node], nodes=None, cliques: Iterable[Incomplete
3737
def number_of_cliques(G, nodes=None, cliques=None) -> int | dict[Incomplete, Incomplete]: ...
3838
@_dispatchable
3939
def max_weight_clique(G, weight="weight") -> tuple[Incomplete, Incomplete]: ...
40+
41+
class MaxWeightClique:
42+
G: Graph[Incomplete]
43+
incumbent_nodes: list[Incomplete]
44+
incumbent_weight: int
45+
node_weights: dict[Incomplete, int]
46+
def __init__(self, G: Graph[_Node], weight): ...
47+
def update_incumbent_if_improved(self, C, C_weight): ...
48+
def greedily_find_independent_set(self, P): ...
49+
def find_branching_nodes(self, P, target): ...
50+
def expand(self, C, C_weight, P): ...
51+
def find_max_weight_clique(self): ...

stubs/networkx/networkx/algorithms/coloring/equitable_coloring.pyi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,13 @@ __all__ = ["equitable_color"]
1111
def is_coloring(G: Graph[_Node], coloring: SupportsGetItem[Incomplete, Incomplete]) -> bool: ...
1212
@_dispatchable
1313
def is_equitable(G: Graph[_Node], coloring: Mapping[Incomplete, Incomplete], num_colors: SupportsIndex | None = None) -> bool: ...
14+
def make_C_from_F(F): ...
15+
def make_N_from_L_C(L, C): ...
16+
def make_H_from_C_N(C, N): ...
17+
def change_color(u, X, Y, N, H, F, C, L): ...
18+
def move_witnesses(src_color, dst_color, N, H, F, C, T_cal, L): ...
19+
@_dispatchable
20+
def pad_graph(G: Graph[_Node], num_colors): ...
21+
def procedure_P(V_minus, V_plus, N, H, F, C, L, excluded_colors=None): ...
1422
@_dispatchable
1523
def equitable_color(G: Graph[_Node], num_colors): ...

stubs/networkx/networkx/algorithms/coloring/greedy_coloring.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from _typeshed import Incomplete
2-
from collections.abc import Generator
2+
from collections.abc import Callable, Generator
3+
from typing import Final
34

45
from networkx.classes.graph import Graph, _Node
56
from networkx.utils.backends import _dispatchable
@@ -32,5 +33,8 @@ def strategy_connected_sequential_dfs(G, colors): ...
3233
def strategy_connected_sequential(G, colors, traversal: str = "bfs") -> Generator[Incomplete, None, None]: ...
3334
@_dispatchable
3435
def strategy_saturation_largest_first(G, colors) -> Generator[Incomplete, None, Incomplete]: ...
36+
37+
STRATEGIES: Final[dict[str, Callable[..., Incomplete]]]
38+
3539
@_dispatchable
3640
def greedy_color(G: Graph[_Node], strategy="largest_first", interchange: bool = False): ...

0 commit comments

Comments
 (0)