Skip to content

Merge networkx from python-type-stubs #14038

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

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 4 additions & 2 deletions stubs/networkx/networkx/algorithms/approximation/clique.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from _typeshed import Incomplete

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

__all__ = ["clique_removal", "max_clique", "large_clique_size", "maximum_independent_set"]

@_dispatchable
def maximum_independent_set(G: Graph[_Node]): ...
def maximum_independent_set(G: Graph[_Node]) -> set[Incomplete]: ...
@_dispatchable
def max_clique(G: Graph[_Node]): ...
def max_clique(G: Graph[_Node]) -> set[Incomplete]: ...
@_dispatchable
def clique_removal(G: Graph[_Node]): ...
@_dispatchable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ from numpy.random import RandomState
__all__ = ["average_clustering"]

@_dispatchable
def average_clustering(G: Graph[_Node], trials: int = 1000, seed: int | RandomState | None = None): ...
def average_clustering(G: Graph[_Node], trials: int = 1000, seed: int | RandomState | None = None) -> float: ...
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ def local_node_connectivity(G: Graph[_Node], source: _Node, target: _Node, cutof
@_dispatchable
def node_connectivity(G: Graph[_Node], s: _Node | None = None, t: _Node | None = None): ...
@_dispatchable
def all_pairs_node_connectivity(G: Graph[_Node], nbunch: Iterable[Incomplete] | None = None, cutoff: int | None = None): ...
def all_pairs_node_connectivity(
G: Graph[_Node], nbunch: Iterable[Incomplete] | None = None, cutoff: int | None = None
) -> dict[Incomplete, dict[Incomplete, Incomplete]]: ...
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from _typeshed import Incomplete

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

__all__ = ["min_weighted_dominating_set", "min_edge_dominating_set"]

@_dispatchable
def min_weighted_dominating_set(G: Graph[_Node], weight: str | None = None): ...
def min_weighted_dominating_set(G: Graph[_Node], weight: str | None = None) -> set[Incomplete]: ...
@_dispatchable
def min_edge_dominating_set(G: Graph[_Node]): ...
def min_edge_dominating_set(G: Graph[_Node]) -> set[Incomplete]: ...
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from _typeshed import Incomplete
from collections import defaultdict

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

__all__ = ["k_components"]

@_dispatchable
def k_components(G: Graph[_Node], min_density: float = 0.95): ...
def k_components(G: Graph[_Node], min_density: float = 0.95) -> defaultdict[Incomplete, list[Incomplete]]: ...
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from _typeshed import Incomplete

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

__all__ = ["min_maximal_matching"]

@_dispatchable
def min_maximal_matching(G: Graph[_Node]): ...
def min_maximal_matching(G: Graph[_Node]) -> set[Incomplete]: ...
6 changes: 5 additions & 1 deletion stubs/networkx/networkx/algorithms/approximation/maxcut.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from _typeshed import Incomplete
from collections.abc import Iterable

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
Expand All @@ -12,5 +13,8 @@ def randomized_partitioning(
): ...
@_dispatchable
def one_exchange(
G: Graph[_Node], initial_cut: set[Incomplete] | None = None, seed: int | RandomState | None = None, weight: str | None = None
G: Graph[_Node],
initial_cut: Iterable[Incomplete] | None = None,
seed: int | RandomState | None = None,
weight: str | None = None,
): ...
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from _typeshed import Incomplete, SupportsLenAndGetItem
from collections.abc import Callable, Mapping
from typing import Any, TypeVar
from collections.abc import Callable, Iterable, Mapping
from typing import Any, Literal, TypeVar

from networkx.classes.digraph import DiGraph
from networkx.classes.graph import Graph, _Node
Expand All @@ -15,13 +15,12 @@ __all__ = [
"simulated_annealing_tsp",
"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): ...
def christofides(G: Graph[_Node], weight: str | None = "weight", tree: Graph[_Node] | None = None) -> list[Incomplete]: ...
@_dispatchable
def traveling_salesman_problem(
G: Graph[_Node],
Expand All @@ -30,7 +29,7 @@ def traveling_salesman_problem(
cycle: bool = True,
method: Callable[..., Incomplete] | None = None,
**kwargs,
): ...
) -> list[Incomplete]: ...
@_dispatchable
def asadpour_atsp(
G: DiGraph[_Node], weight: str | None = "weight", seed: int | RandomState | None = None, source: str | None = None
Expand All @@ -57,7 +56,7 @@ def simulated_annealing_tsp(
@_dispatchable
def threshold_accepting_tsp(
G: Graph[_Node],
init_cycle,
init_cycle: Literal["greedy"] | Iterable[Incomplete],
weight: str | None = "weight",
source=None,
threshold: int | None = 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from _typeshed import Incomplete

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

__all__ = ["min_weighted_vertex_cover"]

@_dispatchable
def min_weighted_vertex_cover(G: Graph[_Node], weight: str | None = None): ...
def min_weighted_vertex_cover(G: Graph[_Node], weight: str | None = None) -> set[Incomplete]: ...
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from _typeshed import Incomplete
from collections.abc import Iterable
from typing import Literal

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
Expand All @@ -8,5 +9,9 @@ __all__ = ["average_degree_connectivity"]

@_dispatchable
def average_degree_connectivity(
G: Graph[_Node], source="in+out", target="in+out", nodes: Iterable[Incomplete] | None = None, weight: str | None = None
): ...
G: Graph[_Node],
source: Literal["in+out", "out", "in"] = "in+out",
target: Literal["in+out", "out", "in"] = "in+out",
nodes: Iterable[Incomplete] | None = None,
weight: str | None = None,
) -> dict[Incomplete, int | float]: ...
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ __all__ = [
@_dispatchable
def degree_assortativity_coefficient(
G: Graph[_Node], x: str = "out", y: str = "in", weight: str | None = None, nodes: Iterable[Incomplete] | None = None
): ...
) -> float: ...
@_dispatchable
def degree_pearson_correlation_coefficient(
G: Graph[_Node], x: str = "out", y: str = "in", weight: str | None = None, nodes: Iterable[Incomplete] | None = None
): ...
) -> float: ...
@_dispatchable
def attribute_assortativity_coefficient(G: Graph[_Node], attribute: str, nodes: Iterable[Incomplete] | None = None): ...
def attribute_assortativity_coefficient(G: Graph[_Node], attribute: str, nodes: Iterable[Incomplete] | None = None) -> float: ...
@_dispatchable
def numeric_assortativity_coefficient(G: Graph[_Node], attribute: str, nodes: Iterable[Incomplete] | None = None): ...
def numeric_assortativity_coefficient(G: Graph[_Node], attribute: str, nodes: Iterable[Incomplete] | None = None) -> float: ...
def attribute_ac(M) -> float: ...
6 changes: 3 additions & 3 deletions stubs/networkx/networkx/algorithms/assortativity/mixing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ __all__ = ["attribute_mixing_matrix", "attribute_mixing_dict", "degree_mixing_ma
@_dispatchable
def attribute_mixing_dict(
G: Graph[_Node], attribute: str, nodes: Iterable[Incomplete] | None = None, normalized: bool = False
): ...
) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def attribute_mixing_matrix(
G: Graph[_Node],
Expand All @@ -21,7 +21,7 @@ def attribute_mixing_matrix(
@_dispatchable
def degree_mixing_dict(
G: Graph[_Node], x: str = "out", y: str = "in", weight: str | None = None, nodes=None, normalized: bool = False
): ...
) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def degree_mixing_matrix(
G: Graph[_Node],
Expand All @@ -33,4 +33,4 @@ def degree_mixing_matrix(
mapping: SupportsGetItem[Incomplete, Incomplete] | None = None,
): ...
@_dispatchable
def mixing_dict(xy, normalized: bool = False): ...
def mixing_dict(xy, normalized: bool = False) -> dict[Incomplete, Incomplete]: ...
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ def average_neighbor_degree(
target: str | None = "out",
nodes: Iterable[Incomplete] | None = None,
weight: str | None = None,
): ...
) -> dict[Incomplete, Incomplete]: ...
2 changes: 1 addition & 1 deletion stubs/networkx/networkx/algorithms/asteroidal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from networkx.utils.backends import _dispatchable
__all__ = ["is_at_free", "find_asteroidal_triple"]

@_dispatchable
def find_asteroidal_triple(G: Graph[_Node]): ...
def find_asteroidal_triple(G: Graph[_Node]) -> list[Incomplete] | None: ...
@_dispatchable
def is_at_free(G: Graph[_Node]) -> bool: ...
@_dispatchable
Expand Down
8 changes: 4 additions & 4 deletions stubs/networkx/networkx/algorithms/bipartite/basic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ from networkx.utils.backends import _dispatchable
__all__ = ["is_bipartite", "is_bipartite_node_set", "color", "sets", "density", "degrees"]

@_dispatchable
def color(G: Graph[_Node]): ...
def color(G: Graph[_Node]) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def is_bipartite(G: Graph[_Node]) -> bool: ...
@_dispatchable
def is_bipartite_node_set(G: Graph[_Node], nodes: Iterable[Incomplete]) -> bool: ...
@_dispatchable
def sets(G: Graph[_Node], top_nodes: Iterable[Incomplete] | None = None): ...
def sets(G: Graph[_Node], top_nodes: Iterable[Incomplete] | None = None) -> tuple[set[Incomplete], set[Incomplete]]: ...
@_dispatchable
def density(B: Graph[_Node], nodes): ...
def density(B: Graph[_Node], nodes) -> float: ...
@_dispatchable
def degrees(B: Graph[_Node], nodes, weight: str | None = None): ...
def degrees(B: Graph[_Node], nodes, weight: str | None = None) -> tuple[Incomplete, Incomplete]: ...
8 changes: 5 additions & 3 deletions stubs/networkx/networkx/algorithms/bipartite/centrality.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from _typeshed import Incomplete

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

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

@_dispatchable
def degree_centrality(G: Graph[_Node], nodes): ...
def degree_centrality(G: Graph[_Node], nodes) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def betweenness_centrality(G: Graph[_Node], nodes): ...
def betweenness_centrality(G: Graph[_Node], nodes) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def closeness_centrality(G: Graph[_Node], nodes, normalized: bool | None = True): ...
def closeness_centrality(G: Graph[_Node], nodes, normalized: bool | None = True) -> dict[Incomplete, Incomplete]: ...
8 changes: 5 additions & 3 deletions stubs/networkx/networkx/algorithms/bipartite/cluster.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ 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"): ...
def latapy_clustering(
G: Graph[_Node], nodes: Iterable[Incomplete] | None = None, mode: str = "dot"
) -> dict[Incomplete, Incomplete]: ...

clustering = latapy_clustering

@_dispatchable
def average_clustering(G: Graph[_Node], nodes: Iterable[Incomplete] | None = None, mode: str = "dot"): ...
def average_clustering(G: Graph[_Node], nodes: Iterable[Incomplete] | None = None, mode: str = "dot") -> float: ...
@_dispatchable
def robins_alexander_clustering(G: Graph[_Node]): ...
def robins_alexander_clustering(G: Graph[_Node]) -> float: ...
2 changes: 1 addition & 1 deletion stubs/networkx/networkx/algorithms/bipartite/covering.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ from networkx.utils.backends import _dispatchable
__all__ = ["min_edge_cover"]

@_dispatchable
def min_edge_cover(G: Graph[_Node], matching_algorithm: Callable[..., Incomplete] | None = None): ...
def min_edge_cover(G: Graph[_Node], matching_algorithm: Callable[..., Incomplete] | None = None) -> set[Incomplete]: ...
19 changes: 14 additions & 5 deletions stubs/networkx/networkx/algorithms/bipartite/edgelist.pyi
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
from _typeshed import Incomplete
from collections.abc import Generator
from collections.abc import Generator, Iterable

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

__all__ = ["generate_edgelist", "write_edgelist", "parse_edgelist", "read_edgelist"]

@_dispatchable
def write_edgelist(G, path, comments: str = "#", delimiter: str = " ", data: bool = True, encoding: str = "utf-8") -> None: ...
def write_edgelist(
G: Graph[_Node],
path,
comments: str = "#",
delimiter: str = " ",
data: bool | Iterable[Incomplete] = True,
encoding: str = "utf-8",
) -> None: ...
@_dispatchable
def generate_edgelist(G, delimiter: str = " ", data: bool = True) -> Generator[Incomplete, None, None]: ...
def generate_edgelist(
G: Graph[_Node], delimiter: str = " ", data: bool | Iterable[Incomplete] = True
) -> Generator[str, None, None]: ...
@_dispatchable
def parse_edgelist(
lines,
comments: str | None = "#",
delimiter: str | None = None,
create_using: Graph[_Node] | None = None,
nodetype=None,
data=True,
data: bool | Iterable[Incomplete] = True,
): ...
@_dispatchable
def read_edgelist(
Expand All @@ -26,7 +35,7 @@ def read_edgelist(
delimiter: str | None = None,
create_using=None,
nodetype=None,
data=True,
data: bool | Iterable[Incomplete] = True,
edgetype=None,
encoding: str | None = "utf-8",
): ...
14 changes: 7 additions & 7 deletions stubs/networkx/networkx/algorithms/bipartite/generators.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from _typeshed import Incomplete
from collections.abc import Iterable
from collections.abc import Collection

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
Expand All @@ -20,24 +20,24 @@ __all__ = [
def complete_bipartite_graph(n1, n2, create_using: Graph[_Node] | None = None): ...
@_dispatchable
def configuration_model(
aseq: Iterable[Incomplete],
bseq: Iterable[Incomplete],
aseq: Collection[Incomplete],
bseq: Collection[Incomplete],
create_using: Graph[_Node] | None = None,
seed: int | RandomState | None = None,
): ...
@_dispatchable
def havel_hakimi_graph(aseq: Iterable[Incomplete], bseq: Iterable[Incomplete], create_using: Graph[_Node] | None = None): ...
def havel_hakimi_graph(aseq: Collection[Incomplete], bseq: Collection[Incomplete], create_using: Graph[_Node] | None = None): ...
@_dispatchable
def reverse_havel_hakimi_graph(
aseq: Iterable[Incomplete], bseq: Iterable[Incomplete], create_using: Graph[_Node] | None = None
aseq: Collection[Incomplete], bseq: Collection[Incomplete], create_using: Graph[_Node] | None = None
): ...
@_dispatchable
def alternating_havel_hakimi_graph(
aseq: Iterable[Incomplete], bseq: Iterable[Incomplete], create_using: Graph[_Node] | None = None
aseq: Collection[Incomplete], bseq: Collection[Incomplete], create_using: Graph[_Node] | None = None
): ...
@_dispatchable
def preferential_attachment_graph(
aseq: Iterable[Incomplete], p: float, create_using: Graph[_Node] | None = None, seed: int | RandomState | None = None
aseq: Collection[Incomplete], p: float, create_using: Graph[_Node] | None = None, seed: int | RandomState | None = None
): ...
@_dispatchable
def random_graph(n: int, m: int, p: float, seed: int | RandomState | None = None, directed: bool | None = False): ...
Expand Down
12 changes: 5 additions & 7 deletions stubs/networkx/networkx/algorithms/bipartite/matching.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import Incomplete, SupportsGetItem
from _typeshed import Incomplete
from collections.abc import Iterable

from networkx.classes.graph import Graph, _Node
Expand All @@ -7,17 +7,15 @@ from networkx.utils.backends import _dispatchable
__all__ = ["maximum_matching", "hopcroft_karp_matching", "eppstein_matching", "to_vertex_cover", "minimum_weight_full_matching"]

@_dispatchable
def hopcroft_karp_matching(G: Graph[_Node], top_nodes: Iterable[_Node] | None = None): ...
def hopcroft_karp_matching(G: Graph[_Node], top_nodes: Iterable[_Node] | None = None) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def eppstein_matching(G: Graph[_Node], top_nodes: Iterable[Incomplete] | None = None): ...
def eppstein_matching(G: Graph[_Node], top_nodes: Iterable[Incomplete] | None = None) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def to_vertex_cover(
G: Graph[_Node], matching: SupportsGetItem[Incomplete, Incomplete], top_nodes: Iterable[Incomplete] | None = None
): ...
def to_vertex_cover(G: Graph[_Node], matching: Iterable[Incomplete], top_nodes: Iterable[Incomplete] | None = None): ...

maximum_matching = hopcroft_karp_matching

@_dispatchable
def minimum_weight_full_matching(
G: Graph[_Node], top_nodes: Iterable[Incomplete] | None = None, weight: str | None = "weight"
): ...
) -> dict[Incomplete, Incomplete]: ...
Loading