diff --git a/stubs/networkx/@tests/stubtest_allowlist.txt b/stubs/networkx/@tests/stubtest_allowlist.txt index c55b28c08921..42dc072b15bb 100644 --- a/stubs/networkx/@tests/stubtest_allowlist.txt +++ b/stubs/networkx/@tests/stubtest_allowlist.txt @@ -40,7 +40,4 @@ networkx(\.algorithms)?(\.tree)?(\.mst)?\.SpanningTreeIterator\.Partition\._DT networkx(\.algorithms)?(\.tree)?(\.branchings)?\.ArborescenceIterator\.Partition\._DT # variable differs from runtime type abc.ABCMeta -networkx.classes.reportviews.EdgeView.dataview -networkx.classes.reportviews.InEdgeView.dataview -networkx.classes.reportviews.OutEdgeView.dataview -networkx.classes.reportviews.OutMultiEdgeView.dataview +networkx\.classes\.reportviews\.\w*EdgeView\.dataview diff --git a/stubs/networkx/networkx/__init__.pyi b/stubs/networkx/networkx/__init__.pyi index 7e5d6b1ec86a..bdd328fb405a 100644 --- a/stubs/networkx/networkx/__init__.pyi +++ b/stubs/networkx/networkx/__init__.pyi @@ -1,3 +1,5 @@ +from typing import Final + from networkx.algorithms import * from networkx.classes import * from networkx.classes import filters as filters @@ -24,3 +26,5 @@ from . import ( relabel as relabel, utils as utils, ) + +__version__: Final[str] diff --git a/stubs/networkx/networkx/algorithms/__init__.pyi b/stubs/networkx/networkx/algorithms/__init__.pyi index 57141f108e16..9a9c70d111c1 100644 --- a/stubs/networkx/networkx/algorithms/__init__.pyi +++ b/stubs/networkx/networkx/algorithms/__init__.pyi @@ -118,6 +118,7 @@ from networkx.algorithms.structuralholes import * from networkx.algorithms.summarization import * from networkx.algorithms.swap import * from networkx.algorithms.time_dependent import * +from networkx.algorithms.tournament import is_tournament as is_tournament from networkx.algorithms.traversal import * from networkx.algorithms.tree.branchings import ( ArborescenceIterator as ArborescenceIterator, diff --git a/stubs/networkx/networkx/algorithms/approximation/traveling_salesman.pyi b/stubs/networkx/networkx/algorithms/approximation/traveling_salesman.pyi index 7d0b61f6f407..acf37c745376 100644 --- a/stubs/networkx/networkx/algorithms/approximation/traveling_salesman.pyi +++ b/stubs/networkx/networkx/algorithms/approximation/traveling_salesman.pyi @@ -1,5 +1,6 @@ -from _typeshed import Incomplete -from collections.abc import Callable +from _typeshed import Incomplete, SupportsLenAndGetItem +from collections.abc import Callable, Mapping +from typing import Any, TypeVar from networkx.classes.digraph import DiGraph from networkx.classes.graph import Graph, _Node @@ -15,6 +16,10 @@ __all__ = [ "threshold_accepting_tsp", ] +_SupportsLenAndGetItemT = TypeVar("_SupportsLenAndGetItemT", bound=SupportsLenAndGetItem[Any]) + +def swap_two_nodes(soln: _SupportsLenAndGetItemT, seed) -> _SupportsLenAndGetItemT: ... +def move_one_node(soln: _SupportsLenAndGetItemT, seed) -> _SupportsLenAndGetItemT: ... @_dispatchable def christofides(G: Graph[_Node], weight: str | None = "weight", tree: Graph[_Node] | None = None): ... @_dispatchable @@ -31,6 +36,10 @@ def asadpour_atsp( G: DiGraph[_Node], weight: str | None = "weight", seed: int | RandomState | None = None, source: str | None = None ): ... @_dispatchable +def held_karp_ascent(G: Graph[_Node], weight="weight"): ... +@_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): ... @_dispatchable def simulated_annealing_tsp( diff --git a/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi b/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi index 0b970f4c5cc1..02b275350005 100644 --- a/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi +++ b/stubs/networkx/networkx/algorithms/approximation/treewidth.pyi @@ -15,3 +15,7 @@ class MinDegreeHeuristic: def __init__(self, graph) -> None: ... def best_node(self, graph): ... + +def min_fill_in_heuristic(graph) -> Incomplete | None: ... +@_dispatchable +def treewidth_decomp(G: Graph[_Node], heuristic=...) -> tuple[int, Graph[_Node]]: ... diff --git a/stubs/networkx/networkx/algorithms/asteroidal.pyi b/stubs/networkx/networkx/algorithms/asteroidal.pyi index 8e3f726b7839..8745fe1accbf 100644 --- a/stubs/networkx/networkx/algorithms/asteroidal.pyi +++ b/stubs/networkx/networkx/algorithms/asteroidal.pyi @@ -1,3 +1,5 @@ +from _typeshed import Incomplete + from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable @@ -7,3 +9,5 @@ __all__ = ["is_at_free", "find_asteroidal_triple"] def find_asteroidal_triple(G: Graph[_Node]): ... @_dispatchable def is_at_free(G: Graph[_Node]) -> bool: ... +@_dispatchable +def create_component_structure(G: Graph[_Node]) -> dict[Incomplete, Incomplete]: ... diff --git a/stubs/networkx/networkx/algorithms/bipartite/cluster.pyi b/stubs/networkx/networkx/algorithms/bipartite/cluster.pyi index d4fffe4ed70a..0931bb9f735d 100644 --- a/stubs/networkx/networkx/algorithms/bipartite/cluster.pyi +++ b/stubs/networkx/networkx/algorithms/bipartite/cluster.pyi @@ -1,11 +1,17 @@ from _typeshed import Incomplete -from collections.abc import Iterable +from collections.abc import Callable, Iterable from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable __all__ = ["clustering", "average_clustering", "latapy_clustering", "robins_alexander_clustering"] +def cc_dot(nu, nv) -> float: ... +def cc_max(nu, nv) -> float: ... +def cc_min(nu, nv) -> float: ... + +modes: dict[str, Callable[[Incomplete, Incomplete], float]] + @_dispatchable def latapy_clustering(G: Graph[_Node], nodes: Iterable[Incomplete] | None = None, mode: str = "dot"): ... diff --git a/stubs/networkx/networkx/algorithms/clique.pyi b/stubs/networkx/networkx/algorithms/clique.pyi index 3fa315dcb846..06405d42c2bf 100644 --- a/stubs/networkx/networkx/algorithms/clique.pyi +++ b/stubs/networkx/networkx/algorithms/clique.pyi @@ -37,3 +37,15 @@ def node_clique_number(G: Graph[_Node], nodes=None, cliques: Iterable[Incomplete def number_of_cliques(G, nodes=None, cliques=None) -> int | dict[Incomplete, Incomplete]: ... @_dispatchable def max_weight_clique(G, weight="weight") -> tuple[Incomplete, Incomplete]: ... + +class MaxWeightClique: + G: Graph[Incomplete] + incumbent_nodes: list[Incomplete] + incumbent_weight: int + node_weights: dict[Incomplete, int] + def __init__(self, G: Graph[_Node], weight): ... + def update_incumbent_if_improved(self, C, C_weight): ... + def greedily_find_independent_set(self, P): ... + def find_branching_nodes(self, P, target): ... + def expand(self, C, C_weight, P): ... + def find_max_weight_clique(self): ... diff --git a/stubs/networkx/networkx/algorithms/coloring/equitable_coloring.pyi b/stubs/networkx/networkx/algorithms/coloring/equitable_coloring.pyi index 57557b5987de..dffd5c269c0e 100644 --- a/stubs/networkx/networkx/algorithms/coloring/equitable_coloring.pyi +++ b/stubs/networkx/networkx/algorithms/coloring/equitable_coloring.pyi @@ -11,5 +11,13 @@ __all__ = ["equitable_color"] def is_coloring(G: Graph[_Node], coloring: SupportsGetItem[Incomplete, Incomplete]) -> bool: ... @_dispatchable def is_equitable(G: Graph[_Node], coloring: Mapping[Incomplete, Incomplete], num_colors: SupportsIndex | None = None) -> bool: ... +def make_C_from_F(F): ... +def make_N_from_L_C(L, C): ... +def make_H_from_C_N(C, N): ... +def change_color(u, X, Y, N, H, F, C, L): ... +def move_witnesses(src_color, dst_color, N, H, F, C, T_cal, L): ... +@_dispatchable +def pad_graph(G: Graph[_Node], num_colors): ... +def procedure_P(V_minus, V_plus, N, H, F, C, L, excluded_colors=None): ... @_dispatchable def equitable_color(G: Graph[_Node], num_colors): ... diff --git a/stubs/networkx/networkx/algorithms/coloring/greedy_coloring.pyi b/stubs/networkx/networkx/algorithms/coloring/greedy_coloring.pyi index 9b7943f13bf2..0ab460edd460 100644 --- a/stubs/networkx/networkx/algorithms/coloring/greedy_coloring.pyi +++ b/stubs/networkx/networkx/algorithms/coloring/greedy_coloring.pyi @@ -1,5 +1,6 @@ from _typeshed import Incomplete -from collections.abc import Generator +from collections.abc import Callable, Generator +from typing import Final from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable @@ -32,5 +33,8 @@ def strategy_connected_sequential_dfs(G, colors): ... def strategy_connected_sequential(G, colors, traversal: str = "bfs") -> Generator[Incomplete, None, None]: ... @_dispatchable def strategy_saturation_largest_first(G, colors) -> Generator[Incomplete, None, Incomplete]: ... + +STRATEGIES: Final[dict[str, Callable[..., Incomplete]]] + @_dispatchable def greedy_color(G: Graph[_Node], strategy="largest_first", interchange: bool = False): ... diff --git a/stubs/networkx/networkx/algorithms/community/divisive.pyi b/stubs/networkx/networkx/algorithms/community/divisive.pyi index 4ae890eab5f1..a0c99adae0ef 100644 --- a/stubs/networkx/networkx/algorithms/community/divisive.pyi +++ b/stubs/networkx/networkx/algorithms/community/divisive.pyi @@ -1,13 +1,13 @@ from _typeshed import Incomplete -import networkx as nx from networkx.classes.graph import Graph, _Node +from networkx.utils.backends import _dispatchable __all__ = ["edge_betweenness_partition", "edge_current_flow_betweenness_partition"] -@nx._dispatchable +@_dispatchable def edge_betweenness_partition(G: Graph[_Node], number_of_sets: int, *, weight: str | None = None) -> list[Incomplete]: ... -@nx._dispatchable +@_dispatchable def edge_current_flow_betweenness_partition( G: Graph[_Node], number_of_sets: int, *, weight: str | None = None ) -> list[Incomplete]: ... diff --git a/stubs/networkx/networkx/algorithms/community/lukes.pyi b/stubs/networkx/networkx/algorithms/community/lukes.pyi index 766f478a0336..c5ebcacdc47c 100644 --- a/stubs/networkx/networkx/algorithms/community/lukes.pyi +++ b/stubs/networkx/networkx/algorithms/community/lukes.pyi @@ -1,7 +1,16 @@ +from typing import Final + from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable __all__ = ["lukes_partitioning"] +D_EDGE_W: Final = "weight" +D_EDGE_VALUE: Final[float] +D_NODE_W: Final = "weight" +D_NODE_VALUE: Final = 1 +PKEY: Final = "partitions" +CLUSTER_EVAL_CACHE_SIZE: Final = 2048 + @_dispatchable def lukes_partitioning(G: Graph[_Node], max_size: int, node_weight=None, edge_weight=None): ... diff --git a/stubs/networkx/networkx/algorithms/community/quality.pyi b/stubs/networkx/networkx/algorithms/community/quality.pyi index 2ce826f6e83e..a1d0f4ec3d0a 100644 --- a/stubs/networkx/networkx/algorithms/community/quality.pyi +++ b/stubs/networkx/networkx/algorithms/community/quality.pyi @@ -1,12 +1,21 @@ from networkx.classes.graph import Graph, _Node from networkx.exception import NetworkXError from networkx.utils.backends import _dispatchable +from networkx.utils.decorators import argmap __all__ = ["modularity", "partition_quality"] class NotAPartition(NetworkXError): def __init__(self, G, collection) -> None: ... +require_partition: argmap + +@_dispatchable +def intra_community_edges(G: Graph[_Node], partition): ... +@_dispatchable +def inter_community_edges(G: Graph[_Node], partition): ... +@_dispatchable +def inter_community_non_edges(G: Graph[_Node], partition): ... @_dispatchable def modularity(G: Graph[_Node], communities, weight: str | None = "weight", resolution: float = 1): ... @_dispatchable diff --git a/stubs/networkx/networkx/algorithms/connectivity/edge_augmentation.pyi b/stubs/networkx/networkx/algorithms/connectivity/edge_augmentation.pyi index 7be4e048f1ba..a988852eac92 100644 --- a/stubs/networkx/networkx/algorithms/connectivity/edge_augmentation.pyi +++ b/stubs/networkx/networkx/algorithms/connectivity/edge_augmentation.pyi @@ -1,5 +1,6 @@ -from _typeshed import SupportsGetItem +from _typeshed import Incomplete, SupportsGetItem from collections.abc import Generator +from typing import NamedTuple from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable @@ -18,3 +19,29 @@ def k_edge_augmentation( weight: str | None = None, partial: bool = False, ) -> Generator[tuple[_Node, _Node], None, None]: ... +@_dispatchable +def partial_k_edge_augmentation(G: Graph[_Node], k, avail, weight: str | None = None): ... +@_dispatchable +def one_edge_augmentation(G: Graph[_Node], avail=None, weight: str | None = None, partial: bool = False): ... +@_dispatchable +def bridge_augmentation(G: Graph[_Node], avail=None, weight: str | None = None): ... + +class MetaEdge(NamedTuple): + meta_uv: Incomplete + uv: Incomplete + w: Incomplete + +@_dispatchable +def unconstrained_one_edge_augmentation(G: Graph[_Node]): ... +@_dispatchable +def weighted_one_edge_augmentation(G: Graph[_Node], avail, weight: str | None = None, partial: bool = False): ... +@_dispatchable +def unconstrained_bridge_augmentation(G: Graph[_Node]): ... +@_dispatchable +def weighted_bridge_augmentation(G: Graph[_Node], avail, weight: str | None = None): ... +@_dispatchable +def collapse(G: Graph[_Node], grouped_nodes): ... +@_dispatchable +def complement_edges(G: Graph[_Node]): ... +@_dispatchable +def greedy_k_edge_augmentation(G: Graph[_Node], k, avail=None, weight: str | None = None, seed=None): ... diff --git a/stubs/networkx/networkx/algorithms/connectivity/edge_kcomponents.pyi b/stubs/networkx/networkx/algorithms/connectivity/edge_kcomponents.pyi index 938cae6ec11a..385e41b067b3 100644 --- a/stubs/networkx/networkx/algorithms/connectivity/edge_kcomponents.pyi +++ b/stubs/networkx/networkx/algorithms/connectivity/edge_kcomponents.pyi @@ -21,3 +21,6 @@ class EdgeComponentAuxGraph: def construct(cls, G): ... def k_edge_components(self, k: int) -> Generator[Incomplete, Incomplete, None]: ... def k_edge_subgraphs(self, k: int) -> Generator[Incomplete, Incomplete, None]: ... + +@_dispatchable +def general_k_edge_subgraphs(G: Graph[_Node], k): ... diff --git a/stubs/networkx/networkx/algorithms/connectivity/kcomponents.pyi b/stubs/networkx/networkx/algorithms/connectivity/kcomponents.pyi index 32010e9ed331..e4363950aadf 100644 --- a/stubs/networkx/networkx/algorithms/connectivity/kcomponents.pyi +++ b/stubs/networkx/networkx/algorithms/connectivity/kcomponents.pyi @@ -10,3 +10,4 @@ default_flow_func = edmonds_karp @_dispatchable def k_components(G: Graph[_Node], flow_func: Callable[..., Incomplete] | None = None): ... +def build_k_number_dict(kcomps) -> dict[Incomplete, Incomplete]: ... diff --git a/stubs/networkx/networkx/algorithms/isomorphism/matchhelpers.pyi b/stubs/networkx/networkx/algorithms/isomorphism/matchhelpers.pyi index 2175fb430a40..ce35ad716eda 100644 --- a/stubs/networkx/networkx/algorithms/isomorphism/matchhelpers.pyi +++ b/stubs/networkx/networkx/algorithms/isomorphism/matchhelpers.pyi @@ -1,4 +1,5 @@ from _typeshed import Incomplete +from types import FunctionType from networkx.utils.backends import _dispatchable @@ -14,6 +15,8 @@ __all__ = [ "generic_multiedge_match", ] +def copyfunc(f, name=None) -> FunctionType: ... +def allclose(x, y, rtol: float = 1.0000000000000001e-05, atol=1e-08) -> bool: ... @_dispatchable def categorical_node_match(attr, default): ... diff --git a/stubs/networkx/networkx/algorithms/isomorphism/tree_isomorphism.pyi b/stubs/networkx/networkx/algorithms/isomorphism/tree_isomorphism.pyi index 0497880a4136..ce593814904e 100644 --- a/stubs/networkx/networkx/algorithms/isomorphism/tree_isomorphism.pyi +++ b/stubs/networkx/networkx/algorithms/isomorphism/tree_isomorphism.pyi @@ -3,6 +3,12 @@ from networkx.utils.backends import _dispatchable __all__ = ["rooted_tree_isomorphism", "tree_isomorphism"] +@_dispatchable +def root_trees(t1, root1, t2, root2): ... +@_dispatchable +def assign_levels(G: Graph[_Node], root): ... +def group_by_levels(levels): ... +def generate_isomorphism(v, w, M, ordered_children): ... @_dispatchable def rooted_tree_isomorphism(t1, root1, t2, root2): ... @_dispatchable diff --git a/stubs/networkx/networkx/algorithms/planar_drawing.pyi b/stubs/networkx/networkx/algorithms/planar_drawing.pyi index 197e912ec440..5bf598392b16 100644 --- a/stubs/networkx/networkx/algorithms/planar_drawing.pyi +++ b/stubs/networkx/networkx/algorithms/planar_drawing.pyi @@ -1,6 +1,16 @@ +from _typeshed import Incomplete +from collections.abc import Sequence + from networkx.utils.backends import _dispatchable __all__ = ["combinatorial_embedding_to_pos"] @_dispatchable def combinatorial_embedding_to_pos(embedding, fully_triangulate: bool = False): ... +def set_position(parent, tree, remaining_nodes, delta_x, y_coordinate, pos): ... +def get_canonical_ordering(embedding, outer_face: Sequence[Incomplete]) -> list[Incomplete]: ... +def triangulate_face(embedding, v1, v2): ... +def triangulate_embedding(embedding, fully_triangulate: bool = True): ... +def make_bi_connected( + embedding, starting_node, outgoing_node, edges_counted: set[tuple[Incomplete, Incomplete]] +) -> list[Incomplete]: ... diff --git a/stubs/networkx/networkx/algorithms/planarity.pyi b/stubs/networkx/networkx/algorithms/planarity.pyi index 4aae6dfb9391..946d24741a97 100644 --- a/stubs/networkx/networkx/algorithms/planarity.pyi +++ b/stubs/networkx/networkx/algorithms/planarity.pyi @@ -11,6 +11,10 @@ __all__ = ["check_planarity", "is_planar", "PlanarEmbedding"] def is_planar(G: Graph[_Node]) -> bool: ... @_dispatchable def check_planarity(G: Graph[_Node], counterexample: bool = False): ... +@_dispatchable +def get_counterexample(G: Graph[_Node]) -> Graph[_Node]: ... +@_dispatchable +def get_counterexample_recursive(G: Graph[_Node]) -> Graph[_Node]: ... class Interval: low: Incomplete diff --git a/stubs/networkx/networkx/algorithms/structuralholes.pyi b/stubs/networkx/networkx/algorithms/structuralholes.pyi index 8d1519350ad6..15060cd5752d 100644 --- a/stubs/networkx/networkx/algorithms/structuralholes.pyi +++ b/stubs/networkx/networkx/algorithms/structuralholes.pyi @@ -6,6 +6,10 @@ from networkx.utils.backends import _dispatchable __all__ = ["constraint", "local_constraint", "effective_size"] +@_dispatchable +def mutual_weight(G: Graph[_Node], u, v, weight=None) -> Incomplete | int: ... +@_dispatchable +def normalized_mutual_weight(G: Graph[_Node], u, v, norm=..., weight=None) -> float: ... @_dispatchable def effective_size(G: Graph[_Node], nodes: Iterable[Incomplete] | None = None, weight: str | None = None): ... @_dispatchable diff --git a/stubs/networkx/networkx/algorithms/threshold.pyi b/stubs/networkx/networkx/algorithms/threshold.pyi index 83b4357827b7..d5a0361e2c1e 100644 --- a/stubs/networkx/networkx/algorithms/threshold.pyi +++ b/stubs/networkx/networkx/algorithms/threshold.pyi @@ -8,5 +8,32 @@ __all__ = ["is_threshold_graph", "find_threshold_graph"] @_dispatchable def is_threshold_graph(G: Graph[_Node]) -> bool: ... def is_threshold_sequence(degree_sequence: Sequence[list[int]]) -> bool: ... +def creation_sequence(degree_sequence, with_labels=False, compact=False): ... +def make_compact(creation_sequence): ... +def uncompact(creation_sequence): ... +def creation_sequence_to_weights(creation_sequence): ... +def weights_to_creation_sequence(weights, threshold=1, with_labels=False, compact=False): ... +@_dispatchable +def threshold_graph(creation_sequence, create_using=None): ... +@_dispatchable +def find_alternating_4_cycle(G: Graph[_Node]): ... @_dispatchable def find_threshold_graph(G: Graph[_Node], create_using: Graph[_Node] | None = None): ... +@_dispatchable +def find_creation_sequence(G: Graph[_Node]): ... +def triangles(creation_sequence): ... +def triangle_sequence(creation_sequence): ... +def cluster_sequence(creation_sequence): ... +def degree_sequence(creation_sequence): ... +def density(creation_sequence): ... +def degree_correlation(creation_sequence): ... +def shortest_path(creation_sequence, u, v): ... +def shortest_path_length(creation_sequence, i): ... +def betweenness_sequence(creation_sequence, normalized=True): ... +def eigenvectors(creation_sequence): ... +def spectral_projection(u, eigenpairs): ... +def eigenvalues(creation_sequence): ... +def random_threshold_sequence(n, p, seed=None): ... +def right_d_threshold_sequence(n, m): ... +def left_d_threshold_sequence(n, m): ... +def swap_d(cs, p_split=1.0, p_combine=1.0, seed=None): ... diff --git a/stubs/networkx/networkx/algorithms/traversal/edgebfs.pyi b/stubs/networkx/networkx/algorithms/traversal/edgebfs.pyi index 19c0db4ef67d..60bc903c320c 100644 --- a/stubs/networkx/networkx/algorithms/traversal/edgebfs.pyi +++ b/stubs/networkx/networkx/algorithms/traversal/edgebfs.pyi @@ -1,10 +1,14 @@ from _typeshed import Incomplete from collections.abc import Generator +from typing import Final from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable __all__ = ["edge_bfs"] +FORWARD: Final = "forward" +REVERSE: Final = "reverse" + @_dispatchable def edge_bfs(G: Graph[_Node], source=None, orientation=None) -> Generator[Incomplete, None, Incomplete]: ... diff --git a/stubs/networkx/networkx/algorithms/traversal/edgedfs.pyi b/stubs/networkx/networkx/algorithms/traversal/edgedfs.pyi index d46c0229d271..a511cd2df35b 100644 --- a/stubs/networkx/networkx/algorithms/traversal/edgedfs.pyi +++ b/stubs/networkx/networkx/algorithms/traversal/edgedfs.pyi @@ -1,10 +1,14 @@ from _typeshed import Incomplete from collections.abc import Generator +from typing import Final from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable __all__ = ["edge_dfs"] +FORWARD: Final = "forward" +REVERSE: Final = "reverse" + @_dispatchable def edge_dfs(G: Graph[_Node], source=None, orientation=None) -> Generator[Incomplete, None, Incomplete]: ... diff --git a/stubs/networkx/networkx/algorithms/tree/branchings.pyi b/stubs/networkx/networkx/algorithms/tree/branchings.pyi index 4232605cfb6f..6b08ec183376 100644 --- a/stubs/networkx/networkx/algorithms/tree/branchings.pyi +++ b/stubs/networkx/networkx/algorithms/tree/branchings.pyi @@ -1,6 +1,7 @@ from _typeshed import Incomplete from collections.abc import Iterator from dataclasses import dataclass +from typing import Final from networkx.classes.digraph import DiGraph from networkx.classes.graph import _Node @@ -18,6 +19,11 @@ __all__ = [ "ArborescenceIterator", ] +KINDS: Final[set[str]] +STYLES: Final[dict[str, str]] +INF: Final[float] + +def random_string(L=15, seed=None): ... @_dispatchable def branching_weight(G: DiGraph[_Node], attr: str = "weight", default: float = 1): ... @_dispatchable diff --git a/stubs/networkx/networkx/algorithms/tree/mst.pyi b/stubs/networkx/networkx/algorithms/tree/mst.pyi index 30854ffd12e0..f53727cbf46a 100644 --- a/stubs/networkx/networkx/algorithms/tree/mst.pyi +++ b/stubs/networkx/networkx/algorithms/tree/mst.pyi @@ -1,8 +1,8 @@ from _typeshed import Incomplete -from collections.abc import Iterator +from collections.abc import Callable, Generator, Iterator from dataclasses import dataclass from enum import Enum -from typing import Literal +from typing import Final, Literal from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable @@ -25,6 +25,15 @@ class EdgePartition(Enum): INCLUDED = 1 EXCLUDED = 2 +@_dispatchable +def boruvka_mst_edges(G: Graph[_Node], minimum=True, weight="weight", keys=False, data=True, ignore_nan=False): ... +@_dispatchable +def kruskal_mst_edges(G: Graph[_Node], minimum, weight="weight", keys=True, data=True, ignore_nan=False, partition=None): ... +@_dispatchable +def prim_mst_edges(G: Graph[_Node], minimum, weight="weight", keys=True, data=True, ignore_nan=False): ... + +ALGORITHMS: Final[dict[str, Callable[..., Generator[Incomplete, Incomplete, Incomplete]]]] + @_dispatchable def minimum_spanning_edges( G: Graph[_Node], diff --git a/stubs/networkx/networkx/algorithms/triads.pyi b/stubs/networkx/networkx/algorithms/triads.pyi index d1fe5a3a4859..23da6821cad3 100644 --- a/stubs/networkx/networkx/algorithms/triads.pyi +++ b/stubs/networkx/networkx/algorithms/triads.pyi @@ -1,5 +1,6 @@ from _typeshed import Incomplete from collections.abc import Collection, Generator +from typing import Final from networkx.classes.digraph import DiGraph from networkx.classes.graph import Graph, _Node @@ -8,6 +9,10 @@ from numpy.random import RandomState __all__ = ["triadic_census", "is_triad", "all_triplets", "all_triads", "triads_by_type", "triad_type", "random_triad"] +TRICODES: Final[tuple[int, ...]] +TRIAD_NAMES: Final[tuple[str, ...]] +TRICODE_TO_NAME: Final[dict[int, str]] + @_dispatchable def triadic_census(G: DiGraph[_Node], nodelist: Collection[_Node] | None = None): ... @_dispatchable diff --git a/stubs/networkx/networkx/classes/digraph.pyi b/stubs/networkx/networkx/classes/digraph.pyi index 281da1a62514..90b403fe4b99 100644 --- a/stubs/networkx/networkx/classes/digraph.pyi +++ b/stubs/networkx/networkx/classes/digraph.pyi @@ -16,6 +16,7 @@ class DiGraph(Graph[_Node]): def has_successor(self, u: _Node, v: _Node) -> bool: ... def has_predecessor(self, u: _Node, v: _Node) -> bool: ... def successors(self, n: _Node) -> Iterator[_Node]: ... + neighbors = successors def predecessors(self, n: _Node) -> Iterator[_Node]: ... @cached_property def out_edges(self) -> OutEdgeView[_Node]: ... diff --git a/stubs/networkx/networkx/drawing/nx_pylab.pyi b/stubs/networkx/networkx/drawing/nx_pylab.pyi index acd59457dead..c2730d1b561d 100644 --- a/stubs/networkx/networkx/drawing/nx_pylab.pyi +++ b/stubs/networkx/networkx/drawing/nx_pylab.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete -from collections.abc import Collection, Sequence +from collections.abc import Collection, Iterable, Sequence __all__ = [ "draw", @@ -107,3 +107,6 @@ def draw_spring(G, **kwargs) -> None: ... def draw_shell(G, nlist=None, **kwargs) -> None: ... def draw_planar(G, **kwargs) -> None: ... def draw_forceatlas2(G, **kwargs) -> None: ... +def apply_alpha( + colors, alpha: float | Iterable[float], elem_list, cmap=None, vmin: float | None = None, vmax: float | None = None +): ... diff --git a/stubs/networkx/networkx/generators/atlas.pyi b/stubs/networkx/networkx/generators/atlas.pyi index 4fffc13ca131..5f55b29e57b7 100644 --- a/stubs/networkx/networkx/generators/atlas.pyi +++ b/stubs/networkx/networkx/generators/atlas.pyi @@ -1,7 +1,13 @@ +from importlib.abc import Traversable +from typing import Final + from networkx.utils.backends import _dispatchable __all__ = ["graph_atlas", "graph_atlas_g"] +NUM_GRAPHS: Final = 1253 +ATLAS_FILE: Final[Traversable] + @_dispatchable def graph_atlas(i): ... @_dispatchable diff --git a/stubs/networkx/networkx/generators/directed.pyi b/stubs/networkx/networkx/generators/directed.pyi index 295a3cba39e3..d1a121c985da 100644 --- a/stubs/networkx/networkx/generators/directed.pyi +++ b/stubs/networkx/networkx/generators/directed.pyi @@ -21,4 +21,6 @@ def scale_free_graph( initial_graph=None, ): ... @_dispatchable +def random_uniform_k_out_graph(n: int, k: int, self_loops: bool = True, with_replacement: bool = True, seed=None): ... +@_dispatchable def random_k_out_graph(n, k, alpha, self_loops: bool = True, seed=None): ... diff --git a/stubs/networkx/networkx/generators/internet_as_graphs.pyi b/stubs/networkx/networkx/generators/internet_as_graphs.pyi index f951ee8347c5..a6bd04e98414 100644 --- a/stubs/networkx/networkx/generators/internet_as_graphs.pyi +++ b/stubs/networkx/networkx/generators/internet_as_graphs.pyi @@ -1,9 +1,13 @@ from _typeshed import Incomplete +from collections.abc import Mapping from networkx.utils.backends import _dispatchable __all__ = ["random_internet_as_graph"] +def uniform_int_from_avg(a, m, seed): ... +def choose_pref_attach(degs: Mapping[Incomplete, Incomplete], seed): ... + class AS_graph_generator: seed: Incomplete n_t: Incomplete diff --git a/stubs/networkx/networkx/generators/triads.pyi b/stubs/networkx/networkx/generators/triads.pyi index e0ce3d43241b..1e536b89355c 100644 --- a/stubs/networkx/networkx/generators/triads.pyi +++ b/stubs/networkx/networkx/generators/triads.pyi @@ -1,6 +1,10 @@ +from typing import Final + from networkx.utils.backends import _dispatchable __all__ = ["triad_graph"] +TRIAD_EDGES: Final[dict[str, list[str]]] + @_dispatchable def triad_graph(triad_name): ... diff --git a/stubs/networkx/networkx/readwrite/gml.pyi b/stubs/networkx/networkx/readwrite/gml.pyi index 53be3c51c240..7807d1da9e85 100644 --- a/stubs/networkx/networkx/readwrite/gml.pyi +++ b/stubs/networkx/networkx/readwrite/gml.pyi @@ -1,7 +1,7 @@ from _typeshed import Incomplete from collections.abc import Generator from enum import Enum -from typing import Generic, NamedTuple, TypeVar +from typing import Final, Generic, NamedTuple, TypeVar from networkx.utils.backends import _dispatchable @@ -9,6 +9,9 @@ _T = TypeVar("_T") __all__ = ["read_gml", "parse_gml", "generate_gml", "write_gml"] +def escape(text): ... +def unescape(text): ... +def literal_destringizer(rep: str): ... @_dispatchable def read_gml(path, label: str = "label", destringizer=None): ... @_dispatchable @@ -29,5 +32,9 @@ class Token(NamedTuple, Generic[_T]): line: int position: int +LIST_START_VALUE: Final = "_networkx_list_start" + +def parse_gml_lines(lines, label, destringizer): ... +def literal_stringizer(value) -> str: ... def generate_gml(G, stringizer=None) -> Generator[Incomplete, Incomplete, None]: ... def write_gml(G, path, stringizer=None) -> None: ... diff --git a/stubs/networkx/networkx/readwrite/graph6.pyi b/stubs/networkx/networkx/readwrite/graph6.pyi index 748be2976c4d..3dd12da9f429 100644 --- a/stubs/networkx/networkx/readwrite/graph6.pyi +++ b/stubs/networkx/networkx/readwrite/graph6.pyi @@ -1,3 +1,7 @@ +from _typeshed import Incomplete +from collections.abc import Iterable + +from networkx.classes.graph import Graph, _Node from networkx.utils.backends import _dispatchable __all__ = ["from_graph6_bytes", "read_graph6", "to_graph6_bytes", "write_graph6"] @@ -8,3 +12,6 @@ def to_graph6_bytes(G, nodes=None, header: bool = True): ... @_dispatchable def read_graph6(path): ... def write_graph6(G, path, nodes=None, header: bool = True): ... +def write_graph6_file(G: Graph[_Node], f, nodes: Iterable[Incomplete] | None = None, header: bool = True): ... +def data_to_n(data): ... +def n_to_data(n): ... diff --git a/stubs/networkx/networkx/readwrite/pajek.pyi b/stubs/networkx/networkx/readwrite/pajek.pyi index b34dfb83a4d8..78966d3cab14 100644 --- a/stubs/networkx/networkx/readwrite/pajek.pyi +++ b/stubs/networkx/networkx/readwrite/pajek.pyi @@ -11,3 +11,4 @@ def write_pajek(G, path, encoding: str = "UTF-8") -> None: ... def read_pajek(path, encoding: str = "UTF-8"): ... @_dispatchable def parse_pajek(lines): ... +def make_qstr(t): ... diff --git a/stubs/networkx/networkx/utils/__init__.pyi b/stubs/networkx/networkx/utils/__init__.pyi index 5d8fb921b076..960b428e67c1 100644 --- a/stubs/networkx/networkx/utils/__init__.pyi +++ b/stubs/networkx/networkx/utils/__init__.pyi @@ -1,26 +1,11 @@ -from networkx.utils.backends import _dispatchable as _dispatchable +from networkx.utils.backends import * +from networkx.utils.backends import _dispatchable as _dispatchable # for pytype to see the re-export in networkx/__init__.py from networkx.utils.configs import * from networkx.utils.configs import NetworkXConfig from networkx.utils.decorators import * from networkx.utils.heaps import * - -# should be import * but pytype doesn't understand that _clear_cache is part of __all__ -from networkx.utils.misc import ( - PythonRandomInterface as PythonRandomInterface, - PythonRandomViaNumpyBits as PythonRandomViaNumpyBits, - _clear_cache as _clear_cache, - arbitrary_element as arbitrary_element, - create_py_random_state as create_py_random_state, - create_random_state as create_random_state, - dict_to_numpy_array as dict_to_numpy_array, - edges_equal as edges_equal, - flatten as flatten, - graphs_equal as graphs_equal, - groups as groups, - make_list_of_ints as make_list_of_ints, - nodes_equal as nodes_equal, - pairwise as pairwise, -) +from networkx.utils.misc import * +from networkx.utils.misc import _clear_cache as _clear_cache # for pytype to see the re-export in networkx/__init__.py from networkx.utils.random_sequence import * from networkx.utils.rcm import * from networkx.utils.union_find import * diff --git a/stubs/networkx/networkx/utils/rcm.pyi b/stubs/networkx/networkx/utils/rcm.pyi index cf8ffb8abf2b..c035e5a6673a 100644 --- a/stubs/networkx/networkx/utils/rcm.pyi +++ b/stubs/networkx/networkx/utils/rcm.pyi @@ -1,7 +1,11 @@ from _typeshed import Incomplete from collections.abc import Generator +from networkx.classes.graph import Graph, _Node + __all__ = ["cuthill_mckee_ordering", "reverse_cuthill_mckee_ordering"] def cuthill_mckee_ordering(G, heuristic=None) -> Generator[Incomplete, Incomplete, None]: ... def reverse_cuthill_mckee_ordering(G, heuristic=None): ... +def connected_cuthill_mckee_ordering(G: Graph[_Node], heuristic=None): ... +def pseudo_peripheral_node(G: Graph[_Node]): ...