Skip to content

Commit afc1faa

Browse files
authored
networkx: improve the distance_measures module (#14461)
1 parent 4860c36 commit afc1faa

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed
Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from _typeshed import Incomplete
2-
from collections.abc import Callable
1+
from collections.abc import Callable, Mapping
32
from typing_extensions import TypeAlias
43

54
from networkx.classes.graph import Graph, _Node
@@ -22,27 +21,43 @@ __all__ = [
2221

2322
@_dispatchable
2423
def eccentricity(
25-
G: Graph[_Node], v: _Node | None = None, sp=None, weight: str | _WeightFunction | None = None
26-
) -> Incomplete | dict[Incomplete, Incomplete]: ...
24+
G: Graph[_Node],
25+
v: _Node | None = None,
26+
sp: Mapping[_Node, Mapping[_Node, int]] | None = None,
27+
weight: str | _WeightFunction | None = None,
28+
) -> int | dict[_Node, int]: ... # TODO: overload on v: dict if v is None else int
2729
@_dispatchable
28-
def diameter(G: Graph[_Node], e=None, usebounds: bool = False, weight: str | _WeightFunction | None = None): ...
30+
def diameter(
31+
G: Graph[_Node], e: Mapping[_Node, int] | None = None, usebounds: bool = False, weight: str | _WeightFunction | None = None
32+
) -> int: ...
2933
@_dispatchable
30-
def harmonic_diameter(G, sp=None, *, weight: str | _WeightFunction | None = None) -> float: ...
34+
def harmonic_diameter(
35+
G: Graph[_Node], sp: Mapping[_Node, Mapping[_Node, int]] | None = None, *, weight: str | _WeightFunction | None = None
36+
) -> float: ...
3137
@_dispatchable
3238
def periphery(
33-
G: Graph[_Node], e=None, usebounds: bool = False, weight: str | _WeightFunction | None = None
34-
) -> list[Incomplete]: ...
39+
G: Graph[_Node], e: Mapping[_Node, int] | None = None, usebounds: bool = False, weight: str | _WeightFunction | None = None
40+
) -> list[_Node]: ...
3541
@_dispatchable
36-
def radius(G: Graph[_Node], e=None, usebounds: bool = False, weight: str | _WeightFunction | None = None): ...
42+
def radius(
43+
G: Graph[_Node], e: Mapping[_Node, int] | None = None, usebounds: bool = False, weight: str | _WeightFunction | None = None
44+
) -> int: ...
3745
@_dispatchable
38-
def center(G: Graph[_Node], e=None, usebounds: bool = False, weight: str | _WeightFunction | None = None) -> list[Incomplete]: ...
46+
def center(
47+
G: Graph[_Node], e: Mapping[_Node, int] | None = None, usebounds: bool = False, weight: str | _WeightFunction | None = None
48+
) -> list[_Node]: ...
3949
@_dispatchable
40-
def barycenter(G, weight: str | _WeightFunction | None = None, attr=None, sp=None) -> list[Incomplete]: ...
50+
def barycenter(
51+
G: Graph[_Node],
52+
weight: str | _WeightFunction | None = None,
53+
attr: str | None = None,
54+
sp: Mapping[_Node, Mapping[_Node, int]] | None = None,
55+
) -> list[_Node]: ...
4156
@_dispatchable
4257
def resistance_distance(
43-
G: Graph[_Node], nodeA=None, nodeB=None, weight: str | None = None, invert_weight: bool = True
44-
) -> float | dict[Incomplete, float]: ...
58+
G: Graph[_Node], nodeA: _Node | None = None, nodeB: _Node | None = None, weight: str | None = None, invert_weight: bool = True
59+
) -> float | dict[_Node, float]: ... # TODO: overload on the nodes: float if both are specified else dict
4560
@_dispatchable
46-
def effective_graph_resistance(G, weight: str | None = None, invert_weight: bool = True) -> float: ...
61+
def effective_graph_resistance(G: Graph[_Node], weight: str | None = None, invert_weight: bool = True) -> float: ...
4762
@_dispatchable
48-
def kemeny_constant(G, *, weight: str | None = None) -> float: ...
63+
def kemeny_constant(G: Graph[_Node], *, weight: str | None = None) -> float: ...

0 commit comments

Comments
 (0)