Skip to content

networkx: All return types from python-type-stubs #14256

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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]: ...
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ _SupportsLenAndGetItemT = TypeVar("_SupportsLenAndGetItemT", bound=SupportsLenAn
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 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
Expand Up @@ -9,4 +9,4 @@ __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
): ...
) -> dict[Incomplete, int | float]: ...
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ __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: ...
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]: ...
3 changes: 1 addition & 2 deletions stubs/networkx/networkx/algorithms/bipartite/edgelist.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from _typeshed import Incomplete
from collections.abc import Generator

from networkx.classes.graph import Graph, _Node
Expand All @@ -9,7 +8,7 @@ __all__ = ["generate_edgelist", "write_edgelist", "parse_edgelist", "read_edgeli
@_dispatchable
def write_edgelist(G, path, comments: str = "#", delimiter: str = " ", data: bool = True, encoding: str = "utf-8") -> None: ...
@_dispatchable
def generate_edgelist(G, delimiter: str = " ", data: bool = True) -> Generator[Incomplete, None, None]: ...
def generate_edgelist(G, delimiter: str = " ", data: bool = True) -> Generator[str, None, None]: ...
@_dispatchable
def parse_edgelist(
lines,
Expand Down
6 changes: 3 additions & 3 deletions stubs/networkx/networkx/algorithms/bipartite/matching.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ 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
Expand All @@ -20,4 +20,4 @@ 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]: ...
2 changes: 1 addition & 1 deletion stubs/networkx/networkx/algorithms/bipartite/matrix.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ def biadjacency_matrix(
dtype=None,
weight: str | None = "weight",
format="csr",
): ...
): ... # Return is a complex union of scipy classes depending on the format param
@_dispatchable
def from_biadjacency_matrix(A, create_using: Graph[_Node] | None = None, edge_attribute: str = "weight"): ...
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ from networkx.utils.backends import _dispatchable
__all__ = ["node_redundancy"]

@_dispatchable
def node_redundancy(G: Graph[_Node], nodes: Iterable[Incomplete] | None = None): ...
def node_redundancy(G: Graph[_Node], nodes: Iterable[Incomplete] | None = None) -> dict[Incomplete, float]: ...
4 changes: 3 additions & 1 deletion stubs/networkx/networkx/algorithms/bipartite/spectral.pyi
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__ = ["spectral_bipartivity"]

@_dispatchable
def spectral_bipartivity(G: Graph[_Node], nodes=None, weight: str = "weight"): ...
def spectral_bipartivity(G: Graph[_Node], nodes=None, weight: str = "weight") -> float | dict[Incomplete, Incomplete]: ...
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
from numpy.random import RandomState
Expand All @@ -18,12 +20,12 @@ def approximate_current_flow_betweenness_centrality(
epsilon: float = 0.5,
kmax: int = 10000,
seed: int | RandomState | None = None,
): ...
) -> dict[Incomplete, float]: ...
@_dispatchable
def current_flow_betweenness_centrality(
G: Graph[_Node], normalized: bool | None = True, weight: str | None = None, dtype: type = ..., solver: str = "full"
): ...
) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def edge_current_flow_betweenness_centrality(
G: Graph[_Node], normalized: bool | None = True, weight: str | None = None, dtype: type = ..., solver: str = "full"
): ...
) -> dict[tuple[Incomplete, Incomplete], float]: ...
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from _typeshed import Incomplete
from collections.abc import Iterable

from networkx.classes.graph import Graph, _Node
Expand All @@ -14,7 +15,7 @@ def current_flow_betweenness_centrality_subset(
weight: str | None = None,
dtype: type = ...,
solver: str = "lu",
): ...
) -> dict[Incomplete, float]: ...
@_dispatchable
def edge_current_flow_betweenness_centrality_subset(
G: Graph[_Node],
Expand All @@ -24,4 +25,4 @@ def edge_current_flow_betweenness_centrality_subset(
weight: str | None = None,
dtype: type = ...,
solver: str = "lu",
): ...
) -> dict[tuple[Incomplete, Incomplete], float]: ...
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from _typeshed import Incomplete

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

__all__ = ["current_flow_closeness_centrality", "information_centrality"]

@_dispatchable
def current_flow_closeness_centrality(G: Graph[_Node], weight: str | None = None, dtype: type = ..., solver: str = "lu"): ...
def current_flow_closeness_centrality(
G: Graph[_Node], weight: str | None = None, dtype: type = ..., solver: str = "lu"
) -> dict[Incomplete, float]: ...

information_centrality = current_flow_closeness_centrality
4 changes: 2 additions & 2 deletions stubs/networkx/networkx/algorithms/centrality/eigenvector.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def eigenvector_centrality(
tol: float | None = 1e-06,
nstart: SupportsGetItem[Incomplete, Incomplete] | None = None,
weight: str | None = None,
): ...
) -> dict[Incomplete, float]: ...
@_dispatchable
def eigenvector_centrality_numpy(
G: Graph[_Node], weight: str | None = None, max_iter: int | None = 50, tol: float | None = 0
): ...
) -> dict[Incomplete, Incomplete]: ...
10 changes: 5 additions & 5 deletions stubs/networkx/networkx/algorithms/centrality/group.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ def prominent_group(
endpoints: bool | None = False,
normalized: bool | None = True,
greedy: bool | None = False,
): ...
) -> tuple[float, list[Incomplete]]: ...
@_dispatchable
def group_closeness_centrality(G: Graph[_Node], S: Iterable[Incomplete], weight: str | None = None): ...
def group_closeness_centrality(G: Graph[_Node], S: Iterable[Incomplete], weight: str | None = None) -> float: ...
@_dispatchable
def group_degree_centrality(G: Graph[_Node], S: Iterable[Incomplete]): ...
def group_degree_centrality(G: Graph[_Node], S: Iterable[Incomplete]) -> float: ...
@_dispatchable
def group_in_degree_centrality(G: Graph[_Node], S: Iterable[Incomplete]): ...
def group_in_degree_centrality(G: Graph[_Node], S: Iterable[Incomplete]) -> float: ...
@_dispatchable
def group_out_degree_centrality(G: Graph[_Node], S: Iterable[Incomplete]): ...
def group_out_degree_centrality(G: Graph[_Node], S: Iterable[Incomplete]) -> float: ...
2 changes: 1 addition & 1 deletion stubs/networkx/networkx/algorithms/centrality/harmonic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ __all__ = ["harmonic_centrality"]
@_dispatchable
def harmonic_centrality(
G: Graph[_Node], nbunch: Iterable[Incomplete] | None = None, distance=None, sources: Iterable[Incomplete] | None = None
): ...
) -> dict[Incomplete, int]: ...
4 changes: 2 additions & 2 deletions stubs/networkx/networkx/algorithms/centrality/katz.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ def katz_centrality(
nstart: SupportsGetItem[Incomplete, Incomplete] | None = None,
normalized: bool | None = True,
weight: str | None = None,
): ...
) -> dict[Incomplete, Incomplete]: ...
@_dispatchable
def katz_centrality_numpy(
G: Graph[_Node],
alpha: float = 0.1,
beta: float | SupportsGetItem[Incomplete, Incomplete] | None = 1.0,
normalized: bool = True,
weight: str | None = None,
): ...
) -> dict[Incomplete, Incomplete]: ...
4 changes: 3 additions & 1 deletion stubs/networkx/networkx/algorithms/centrality/load.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 @@ -6,7 +8,7 @@ __all__ = ["load_centrality", "edge_load_centrality"]
@_dispatchable
def newman_betweenness_centrality(
G: Graph[_Node], v=None, cutoff: bool | None = None, normalized: bool | None = True, weight: str | None = None
): ...
) -> float | dict[Incomplete, float]: ...

load_centrality = newman_betweenness_centrality

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def percolation_centrality(
attribute: str | None = "percolation",
states: SupportsGetItem[Incomplete, Incomplete] | None = None,
weight: str | None = None,
): ...
) -> dict[Incomplete, float]: ...
Loading