Skip to content

networkx: Add symbols from python-type-stubs #14084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions stubs/networkx/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions stubs/networkx/networkx/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Final

from networkx.algorithms import *
from networkx.classes import *
from networkx.classes import filters as filters
Expand All @@ -24,3 +26,5 @@ from . import (
relabel as relabel,
utils as utils,
)

__version__: Final[str]
1 change: 1 addition & 0 deletions stubs/networkx/networkx/algorithms/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]]: ...
4 changes: 4 additions & 0 deletions stubs/networkx/networkx/algorithms/asteroidal.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from _typeshed import Incomplete

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

Expand All @@ -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]: ...
8 changes: 7 additions & 1 deletion stubs/networkx/networkx/algorithms/bipartite/cluster.pyi
Original file line number Diff line number Diff line change
@@ -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"): ...

Expand Down
12 changes: 12 additions & 0 deletions stubs/networkx/networkx/algorithms/clique.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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): ...
Original file line number Diff line number Diff line change
Expand Up @@ -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): ...
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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): ...
6 changes: 3 additions & 3 deletions stubs/networkx/networkx/algorithms/community/divisive.pyi
Original file line number Diff line number Diff line change
@@ -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]: ...
9 changes: 9 additions & 0 deletions stubs/networkx/networkx/algorithms/community/lukes.pyi
Original file line number Diff line number Diff line change
@@ -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): ...
9 changes: 9 additions & 0 deletions stubs/networkx/networkx/algorithms/community/quality.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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): ...
Original file line number Diff line number Diff line change
Expand Up @@ -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): ...
Original file line number Diff line number Diff line change
Expand Up @@ -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]: ...
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from _typeshed import Incomplete
from types import FunctionType

from networkx.utils.backends import _dispatchable

Expand All @@ -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): ...

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions stubs/networkx/networkx/algorithms/planar_drawing.pyi
Original file line number Diff line number Diff line change
@@ -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]: ...
4 changes: 4 additions & 0 deletions stubs/networkx/networkx/algorithms/planarity.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions stubs/networkx/networkx/algorithms/structuralholes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions stubs/networkx/networkx/algorithms/threshold.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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): ...
4 changes: 4 additions & 0 deletions stubs/networkx/networkx/algorithms/traversal/edgebfs.pyi
Original file line number Diff line number Diff line change
@@ -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]: ...
4 changes: 4 additions & 0 deletions stubs/networkx/networkx/algorithms/traversal/edgedfs.pyi
Original file line number Diff line number Diff line change
@@ -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]: ...
Loading