Annotate a few NetworkX algorithm types (#11811)

This commit is contained in:
Daniel Darabos
2024-04-23 11:48:49 +02:00
committed by GitHub
parent 312dfe5791
commit af88af1fa6
6 changed files with 42 additions and 28 deletions

View File

@@ -1,17 +1,19 @@
from _typeshed import Incomplete
from networkx.classes.graph import Graph, _Edge, _Node
from networkx.utils.backends import _dispatch
from numpy.random import RandomState
@_dispatch
def betweenness_centrality(
G,
k: Incomplete | None = None,
G: Graph[_Node],
k: int | None = None,
normalized: bool = True,
weight: Incomplete | None = None,
weight: str | None = None,
endpoints: bool = False,
seed: Incomplete | None = None,
): ...
seed: int | RandomState | None = None,
) -> dict[_Node, float]: ...
@_dispatch
def edge_betweenness_centrality(
G, k: Incomplete | None = None, normalized: bool = True, weight: Incomplete | None = None, seed: Incomplete | None = None
): ...
G: Graph[_Node], k: int | None = None, normalized: bool = True, weight: str | None = None, seed: Incomplete | None = None
) -> dict[_Edge[_Node], float]: ...

View File

@@ -1,8 +1,13 @@
from _typeshed import Incomplete
from collections.abc import Iterable
from networkx.classes.graph import Graph, _Edge, _Node
from networkx.utils.backends import _dispatch
@_dispatch
def betweenness_centrality_subset(G, sources, targets, normalized: bool = False, weight: Incomplete | None = None): ...
def betweenness_centrality_subset(
G: Graph[_Node], sources: Iterable[_Node], targets: Iterable[_Node], normalized: bool = False, weight: str | None = None
) -> dict[_Node, float]: ...
@_dispatch
def edge_betweenness_centrality_subset(G, sources, targets, normalized: bool = False, weight: Incomplete | None = None): ...
def edge_betweenness_centrality_subset(
G: Graph[_Node], sources: Iterable[_Node], targets: Iterable[_Node], normalized: bool = False, weight: str | None = None
) -> dict[_Edge[_Node], float]: ...

View File

@@ -1,10 +1,17 @@
from _typeshed import Incomplete
from _typeshed import SupportsGetItem
from networkx.classes.graph import Graph, _Edge, _Node
from networkx.utils.backends import _dispatch
@_dispatch
def closeness_centrality(G, u: Incomplete | None = None, distance: Incomplete | None = None, wf_improved: bool = True): ...
def closeness_centrality(
G: Graph[_Node], u: _Node | None = None, distance: str | None = None, wf_improved: bool = True
) -> dict[_Node, float]: ...
@_dispatch
def incremental_closeness_centrality(
G, edge, prev_cc: Incomplete | None = None, insertion: bool = True, wf_improved: bool = True
): ...
G: Graph[_Node],
edge: _Edge[_Node],
prev_cc: SupportsGetItem[_Node, float] | None = None,
insertion: bool = True,
wf_improved: bool = True,
) -> dict[_Node, float]: ...

View File

@@ -1,8 +1,9 @@
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatch
@_dispatch
def degree_centrality(G): ...
def degree_centrality(G: Graph[_Node]) -> dict[_Node, float]: ...
@_dispatch
def in_degree_centrality(G): ...
def in_degree_centrality(G: Graph[_Node]) -> dict[_Node, float]: ...
@_dispatch
def out_degree_centrality(G): ...
def out_degree_centrality(G: Graph[_Node]) -> dict[_Node, float]: ...

View File

@@ -1,14 +1,13 @@
from _typeshed import Incomplete
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatch
@_dispatch
def dispersion(
G,
u: Incomplete | None = None,
v: Incomplete | None = None,
G: Graph[_Node],
u: _Node | None = None,
v: _Node | None = None,
normalized: bool = True,
alpha: float = 1.0,
b: float = 0.0,
c: float = 0.0,
): ...
) -> dict[_Node, float] | dict[_Node, dict[_Node, float]]: ...

View File

@@ -20,11 +20,11 @@ def to_networkx_graph(
@_dispatch
def to_dict_of_lists(G: Graph[_Node], nodelist: None | Iterable[_Node] = None) -> dict[_Node, list[_Node]]: ...
@_dispatch
def from_dict_of_lists(d: dict[_Node, Iterable[_Node]], create_using: Incomplete | None = None): ...
def to_dict_of_dicts(G, nodelist=None, edge_data=None) -> dict[Incomplete, Incomplete]: ...
def from_dict_of_lists(d: dict[_Node, Iterable[_Node]], create_using: Incomplete | None = None) -> Graph[_Node]: ...
def to_dict_of_dicts(G: Graph[_Node], nodelist=None, edge_data=None) -> dict[Incomplete, Incomplete]: ...
@_dispatch
def from_dict_of_dicts(d, create_using=None, multigraph_input=False): ...
def from_dict_of_dicts(d, create_using=None, multigraph_input=False) -> Graph[Incomplete]: ...
@_dispatch
def to_edgelist(G, nodelist=None): ...
def to_edgelist(G: Graph[_Node], nodelist=None): ...
@_dispatch
def from_edgelist(edgelist, create_using=None): ...
def from_edgelist(edgelist, create_using=None) -> Graph[Incomplete]: ...