Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb7df6d

Browse files
fix: weight parameter type for networkx.algorithms.shortest_paths (#12663)
1 parent 0015ce8 commit eb7df6d

1 file changed

Lines changed: 35 additions & 26 deletions

File tree

  • stubs/networkx/networkx/algorithms/shortest_paths
Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,72 @@
11
from _typeshed import Incomplete
2-
from collections.abc import Generator
2+
from collections.abc import Callable, Generator
3+
from typing import Any
4+
from typing_extensions import TypeAlias
35

46
from networkx.utils.backends import _dispatch
57

8+
# type alias for the weight function
9+
_WeightFunction: TypeAlias = Callable[[Any, Any, dict[str, Any]], float | None]
10+
611
@_dispatch
7-
def dijkstra_path(G, source, target, weight: str = "weight"): ...
12+
def dijkstra_path(G, source, target, weight: str | _WeightFunction = "weight"): ...
813
@_dispatch
9-
def dijkstra_path_length(G, source, target, weight: str = "weight"): ...
14+
def dijkstra_path_length(G, source, target, weight: str | _WeightFunction = "weight"): ...
1015
@_dispatch
11-
def single_source_dijkstra_path(G, source, cutoff: Incomplete | None = None, weight: str = "weight"): ...
16+
def single_source_dijkstra_path(G, source, cutoff: Incomplete | None = None, weight: str | _WeightFunction = "weight"): ...
1217
@_dispatch
13-
def single_source_dijkstra_path_length(G, source, cutoff: Incomplete | None = None, weight: str = "weight"): ...
18+
def single_source_dijkstra_path_length(G, source, cutoff: Incomplete | None = None, weight: str | _WeightFunction = "weight"): ...
1419
@_dispatch
1520
def single_source_dijkstra(
16-
G, source, target: Incomplete | None = None, cutoff: Incomplete | None = None, weight: str = "weight"
21+
G, source, target: Incomplete | None = None, cutoff: Incomplete | None = None, weight: str | _WeightFunction = "weight"
1722
): ...
1823
@_dispatch
19-
def multi_source_dijkstra_path(G, sources, cutoff: Incomplete | None = None, weight: str = "weight"): ...
24+
def multi_source_dijkstra_path(G, sources, cutoff: Incomplete | None = None, weight: str | _WeightFunction = "weight"): ...
2025
@_dispatch
21-
def multi_source_dijkstra_path_length(G, sources, cutoff: Incomplete | None = None, weight: str = "weight"): ...
26+
def multi_source_dijkstra_path_length(G, sources, cutoff: Incomplete | None = None, weight: str | _WeightFunction = "weight"): ...
2227
@_dispatch
2328
def multi_source_dijkstra(
24-
G, sources, target: Incomplete | None = None, cutoff: Incomplete | None = None, weight: str = "weight"
29+
G, sources, target: Incomplete | None = None, cutoff: Incomplete | None = None, weight: str | _WeightFunction = "weight"
2530
): ...
2631
@_dispatch
27-
def dijkstra_predecessor_and_distance(G, source, cutoff: Incomplete | None = None, weight: str = "weight"): ...
32+
def dijkstra_predecessor_and_distance(G, source, cutoff: Incomplete | None = None, weight: str | _WeightFunction = "weight"): ...
2833
@_dispatch
29-
def all_pairs_dijkstra(G, cutoff: Incomplete | None = None, weight: str = "weight") -> Generator[Incomplete, None, None]: ...
34+
def all_pairs_dijkstra(
35+
G, cutoff: Incomplete | None = None, weight: str | _WeightFunction = "weight"
36+
) -> Generator[Incomplete, None, None]: ...
3037
@_dispatch
3138
def all_pairs_dijkstra_path_length(
32-
G, cutoff: Incomplete | None = None, weight: str = "weight"
39+
G, cutoff: Incomplete | None = None, weight: str | _WeightFunction = "weight"
3340
) -> Generator[Incomplete, None, None]: ...
3441
@_dispatch
35-
def all_pairs_dijkstra_path(G, cutoff: Incomplete | None = None, weight: str = "weight") -> Generator[Incomplete, None, None]: ...
42+
def all_pairs_dijkstra_path(
43+
G, cutoff: Incomplete | None = None, weight: str | _WeightFunction = "weight"
44+
) -> Generator[Incomplete, None, None]: ...
3645
@_dispatch
3746
def bellman_ford_predecessor_and_distance(
38-
G, source, target: Incomplete | None = None, weight: str = "weight", heuristic: bool = False
47+
G, source, target: Incomplete | None = None, weight: str | _WeightFunction = "weight", heuristic: bool = False
3948
): ...
4049
@_dispatch
41-
def bellman_ford_path(G, source, target, weight: str = "weight"): ...
50+
def bellman_ford_path(G, source, target, weight: str | _WeightFunction = "weight"): ...
4251
@_dispatch
43-
def bellman_ford_path_length(G, source, target, weight: str = "weight"): ...
52+
def bellman_ford_path_length(G, source, target, weight: str | _WeightFunction = "weight"): ...
4453
@_dispatch
45-
def single_source_bellman_ford_path(G, source, weight: str = "weight"): ...
54+
def single_source_bellman_ford_path(G, source, weight: str | _WeightFunction = "weight"): ...
4655
@_dispatch
47-
def single_source_bellman_ford_path_length(G, source, weight: str = "weight"): ...
56+
def single_source_bellman_ford_path_length(G, source, weight: str | _WeightFunction = "weight"): ...
4857
@_dispatch
49-
def single_source_bellman_ford(G, source, target: Incomplete | None = None, weight: str = "weight"): ...
58+
def single_source_bellman_ford(G, source, target: Incomplete | None = None, weight: str | _WeightFunction = "weight"): ...
5059
@_dispatch
51-
def all_pairs_bellman_ford_path_length(G, weight: str = "weight") -> Generator[Incomplete, None, None]: ...
60+
def all_pairs_bellman_ford_path_length(G, weight: str | _WeightFunction = "weight") -> Generator[Incomplete, None, None]: ...
5261
@_dispatch
53-
def all_pairs_bellman_ford_path(G, weight: str = "weight") -> Generator[Incomplete, None, None]: ...
62+
def all_pairs_bellman_ford_path(G, weight: str | _WeightFunction = "weight") -> Generator[Incomplete, None, None]: ...
5463
@_dispatch
55-
def goldberg_radzik(G, source, weight: str = "weight"): ...
64+
def goldberg_radzik(G, source, weight: str | _WeightFunction = "weight"): ...
5665
@_dispatch
57-
def negative_edge_cycle(G, weight: str = "weight", heuristic: bool = True): ...
66+
def negative_edge_cycle(G, weight: str | _WeightFunction = "weight", heuristic: bool = True): ...
5867
@_dispatch
59-
def find_negative_cycle(G, source, weight: str = "weight"): ...
68+
def find_negative_cycle(G, source, weight: str | _WeightFunction = "weight"): ...
6069
@_dispatch
61-
def bidirectional_dijkstra(G, source, target, weight: str = "weight"): ...
70+
def bidirectional_dijkstra(G, source, target, weight: str | _WeightFunction = "weight"): ...
6271
@_dispatch
63-
def johnson(G, weight: str = "weight"): ...
72+
def johnson(G, weight: str | _WeightFunction = "weight"): ...

0 commit comments

Comments
 (0)