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 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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: 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,7 +15,6 @@ __all__ = [
"simulated_annealing_tsp",
"threshold_accepting_tsp",
]

_SupportsLenAndGetItemT = TypeVar("_SupportsLenAndGetItemT", bound=SupportsLenAndGetItem[Any])

def swap_two_nodes(soln: _SupportsLenAndGetItemT, seed) -> _SupportsLenAndGetItemT: ...
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,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 @@ -23,3 +23,4 @@ def degree_pearson_correlation_coefficient(
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) -> float: ...
def attribute_ac(M) -> float: ...
18 changes: 13 additions & 5 deletions stubs/networkx/networkx/algorithms/bipartite/edgelist.pyi
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
from collections.abc import Generator
from _typeshed import Incomplete
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[str]: ...
def generate_edgelist(G: Graph[_Node], delimiter: str = " ", data: bool | Iterable[Incomplete] = True) -> Generator[str]: ...
@_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 @@ -25,7 +33,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
6 changes: 2 additions & 4 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 @@ -11,9 +11,7 @@ def hopcroft_karp_matching(G: Graph[_Node], top_nodes: Iterable[_Node] | None =
@_dispatchable
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

Expand Down
6 changes: 3 additions & 3 deletions stubs/networkx/networkx/algorithms/bipartite/matrix.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 @@ -9,8 +9,8 @@ __all__ = ["biadjacency_matrix", "from_biadjacency_matrix"]
@_dispatchable
def biadjacency_matrix(
G: Graph[_Node],
row_order: Iterable[_Node],
column_order: Iterable[Incomplete] | None = None,
row_order: Collection[_Node],
column_order: Collection[Incomplete] | None = None,
dtype=None,
weight: str | None = "weight",
format="csr",
Expand Down
4 changes: 2 additions & 2 deletions stubs/networkx/networkx/algorithms/bipartite/projection.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from _typeshed import Incomplete
from collections.abc import Callable, Iterable
from collections.abc import Callable, Collection, Iterable

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
Expand All @@ -15,7 +15,7 @@ __all__ = [
@_dispatchable
def projected_graph(B: Graph[_Node], nodes: Iterable[Incomplete], multigraph: bool = False): ...
@_dispatchable
def weighted_projected_graph(B: Graph[_Node], nodes: Iterable[Incomplete], ratio: bool = False): ...
def weighted_projected_graph(B: Graph[_Node], nodes: Collection[Incomplete], ratio: bool = False): ...
@_dispatchable
def collaboration_weighted_projected_graph(B: Graph[_Node], nodes: Iterable[Incomplete]): ...
@_dispatchable
Expand Down
22 changes: 11 additions & 11 deletions stubs/networkx/networkx/algorithms/boundary.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def edge_boundary(
G: Graph[_Node],
nbunch1: Iterable[Incomplete],
nbunch2: Iterable[Incomplete] | None = None,
data=False,
data: bool | Incomplete = False,
keys: bool = False,
default=None,
) -> Generator[tuple[_Node, _Node], None, None]: ...
Expand All @@ -22,7 +22,7 @@ def edge_boundary(
G: Graph[_Node],
nbunch1: Iterable[Incomplete],
nbunch2: Iterable[Incomplete] | None = None,
data=False,
data: bool | Incomplete = False,
keys: bool = False,
default=None,
) -> Generator[tuple[_Node, _Node, dict[str, Incomplete]], None, None]: ...
Expand All @@ -31,7 +31,7 @@ def edge_boundary(
G: Graph[_Node],
nbunch1: Iterable[Incomplete],
nbunch2: Iterable[Incomplete] | None = None,
data=False,
data: bool | Incomplete = False,
keys: bool = False,
default=None,
) -> Generator[tuple[_Node, _Node, dict[str, Incomplete]], None, None]: ...
Expand All @@ -40,7 +40,7 @@ def edge_boundary(
G: Graph[_Node],
nbunch1: Iterable[Incomplete],
nbunch2: Iterable[Incomplete] | None = None,
data=False,
data: bool | Incomplete = False,
keys: bool = False,
default: _U | None = None,
) -> Generator[tuple[_Node, _Node, dict[str, _U]], None, None]: ...
Expand All @@ -49,7 +49,7 @@ def edge_boundary(
G: Graph[_Node],
nbunch1: Iterable[Incomplete],
nbunch2: Iterable[Incomplete] | None = None,
data=False,
data: bool | Incomplete = False,
keys: bool = False,
default: _U | None = None,
) -> Generator[tuple[_Node, _Node, dict[str, _U]], None, None]: ...
Expand All @@ -58,7 +58,7 @@ def edge_boundary(
G: Graph[_Node],
nbunch1: Iterable[Incomplete],
nbunch2: Iterable[Incomplete] | None = None,
data=False,
data: bool | Incomplete = False,
keys: bool = False,
default=None,
) -> Generator[tuple[_Node, _Node, int], None, None]: ...
Expand All @@ -67,7 +67,7 @@ def edge_boundary(
G: Graph[_Node],
nbunch1: Iterable[Incomplete],
nbunch2: Iterable[Incomplete] | None = None,
data=False,
data: bool | Incomplete = False,
keys: bool = False,
default=None,
) -> Generator[tuple[_Node, _Node, int], None, None]: ...
Expand All @@ -76,7 +76,7 @@ def edge_boundary(
G: Graph[_Node],
nbunch1: Iterable[Incomplete],
nbunch2: Iterable[Incomplete] | None = None,
data=False,
data: bool | Incomplete = False,
keys: bool = False,
default=None,
) -> Generator[tuple[_Node, _Node, int, dict[str, Incomplete]], None, None]: ...
Expand All @@ -85,7 +85,7 @@ def edge_boundary(
G: Graph[_Node],
nbunch1: Iterable[Incomplete],
nbunch2: Iterable[Incomplete] | None = None,
data=False,
data: bool | Incomplete = False,
keys: bool = False,
default=None,
) -> Generator[tuple[_Node, _Node, int, dict[str, Incomplete]], None, None]: ...
Expand All @@ -94,7 +94,7 @@ def edge_boundary(
G: Graph[_Node],
nbunch1: Iterable[Incomplete],
nbunch2: Iterable[Incomplete] | None = None,
data=False,
data: bool | Incomplete = False,
keys: bool = False,
default: _U | None = None,
) -> Generator[tuple[_Node, _Node, int, dict[str, _U]], None, None]: ...
Expand All @@ -103,7 +103,7 @@ def edge_boundary(
G: Graph[_Node],
nbunch1: Iterable[Incomplete],
nbunch2: Iterable[Incomplete] | None = None,
data=False,
data: bool | Incomplete = False,
keys: bool = False,
default: _U | None = None,
) -> Generator[tuple[_Node, _Node, int, dict[str, _U]], None, None]: ...
Expand Down
5 changes: 3 additions & 2 deletions stubs/networkx/networkx/algorithms/centrality/closeness.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from _typeshed import Incomplete, SupportsGetItem
from _typeshed import Incomplete
from collections.abc import Mapping

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
Expand All @@ -13,7 +14,7 @@ def closeness_centrality(
def incremental_closeness_centrality(
G: Graph[_Node],
edge: tuple[Incomplete],
prev_cc: SupportsGetItem[Incomplete, Incomplete] | None = None,
prev_cc: Mapping[Incomplete, Incomplete] | None = None,
insertion: bool | None = True,
wf_improved: bool | None = True,
) -> dict[_Node, float]: ...
5 changes: 3 additions & 2 deletions stubs/networkx/networkx/algorithms/centrality/eigenvector.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from _typeshed import Incomplete, SupportsGetItem
from _typeshed import Incomplete
from collections.abc import Mapping

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
Expand All @@ -10,7 +11,7 @@ def eigenvector_centrality(
G: Graph[_Node],
max_iter: int | None = 100,
tol: float | None = 1e-06,
nstart: SupportsGetItem[Incomplete, Incomplete] | None = None,
nstart: Mapping[Incomplete, Incomplete] | None = None,
weight: str | None = None,
) -> dict[Incomplete, float]: ...
@_dispatchable
Expand Down
3 changes: 2 additions & 1 deletion stubs/networkx/networkx/algorithms/centrality/katz.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from _typeshed import Incomplete, SupportsGetItem
from collections.abc import Iterable

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
Expand All @@ -12,7 +13,7 @@ def katz_centrality(
beta: float | SupportsGetItem[Incomplete, Incomplete] | None = 1.0,
max_iter: int | None = 1000,
tol: float | None = 1e-06,
nstart: SupportsGetItem[Incomplete, Incomplete] | None = None,
nstart: Iterable[Incomplete] | None = None,
normalized: bool | None = True,
weight: str | None = None,
) -> dict[Incomplete, Incomplete]: ...
Expand Down
5 changes: 3 additions & 2 deletions stubs/networkx/networkx/algorithms/centrality/percolation.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from _typeshed import Incomplete, SupportsGetItem
from _typeshed import Incomplete
from collections.abc import Mapping

from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable
Expand All @@ -9,6 +10,6 @@ __all__ = ["percolation_centrality"]
def percolation_centrality(
G: Graph[_Node],
attribute: str | None = "percolation",
states: SupportsGetItem[Incomplete, Incomplete] | None = None,
states: Mapping[Incomplete, Incomplete] | None = None,
weight: str | None = None,
) -> dict[Incomplete, float]: ...
2 changes: 1 addition & 1 deletion stubs/networkx/networkx/algorithms/chordal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ def chordal_graph_cliques(G: Graph[_Node]) -> Generator[frozenset[_Node], None,
@_dispatchable
def chordal_graph_treewidth(G: Graph[_Node]) -> int: ...
@_dispatchable
def complete_to_chordal_graph(G) -> tuple[Incomplete, dict[Incomplete, int]]: ...
def complete_to_chordal_graph(G: Graph[_Node]) -> tuple[Incomplete, dict[Incomplete, int]]: ...
12 changes: 7 additions & 5 deletions stubs/networkx/networkx/algorithms/clique.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ def make_clique_bipartite(
G: Graph[_Node], fpos: bool | None = None, create_using: Graph[_Node] | None = None, name=None
) -> Graph[_Node]: ...
@overload
def node_clique_number(
G: Graph[_Node], nodes=None, cliques: Iterable[Incomplete] | None = None, separate_nodes=False
def node_clique_number( # type: ignore[overload-overlap]
G: Graph[_Node], nodes: Iterable[_Node] | None = None, cliques: Iterable[Incomplete] | None = None, separate_nodes=False
) -> dict[_Node, int]: ...
@overload
def node_clique_number(G: Graph[_Node], nodes=None, cliques: Iterable[Incomplete] | None = None, separate_nodes=False) -> int: ...
def number_of_cliques(G, nodes=None, cliques=None) -> int | dict[Incomplete, Incomplete]: ...
def node_clique_number(
G: Graph[_Node], nodes: _Node, cliques: Iterable[Incomplete] | None = None, separate_nodes=False
) -> int: ...
def number_of_cliques(G: Graph[_Node], nodes=None, cliques=None) -> int | dict[Incomplete, Incomplete]: ...
@_dispatchable
def max_weight_clique(G, weight="weight") -> tuple[list[Incomplete], int]: ...
def max_weight_clique(G: Graph[_Node], weight="weight") -> tuple[list[Incomplete], int]: ...

class MaxWeightClique:
G: Graph[Incomplete]
Expand Down
Loading
Loading