|
1 | 1 | 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 |
3 | 5 |
|
4 | 6 | from networkx.utils.backends import _dispatch |
5 | 7 |
|
| 8 | +# type alias for the weight function |
| 9 | +_WeightFunction: TypeAlias = Callable[[Any, Any, dict[str, Any]], float | None] |
| 10 | + |
6 | 11 | @_dispatch |
7 | | -def dijkstra_path(G, source, target, weight: str = "weight"): ... |
| 12 | +def dijkstra_path(G, source, target, weight: str | _WeightFunction = "weight"): ... |
8 | 13 | @_dispatch |
9 | | -def dijkstra_path_length(G, source, target, weight: str = "weight"): ... |
| 14 | +def dijkstra_path_length(G, source, target, weight: str | _WeightFunction = "weight"): ... |
10 | 15 | @_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"): ... |
12 | 17 | @_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"): ... |
14 | 19 | @_dispatch |
15 | 20 | 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" |
17 | 22 | ): ... |
18 | 23 | @_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"): ... |
20 | 25 | @_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"): ... |
22 | 27 | @_dispatch |
23 | 28 | 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" |
25 | 30 | ): ... |
26 | 31 | @_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"): ... |
28 | 33 | @_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]: ... |
30 | 37 | @_dispatch |
31 | 38 | 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" |
33 | 40 | ) -> Generator[Incomplete, None, None]: ... |
34 | 41 | @_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]: ... |
36 | 45 | @_dispatch |
37 | 46 | 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 |
39 | 48 | ): ... |
40 | 49 | @_dispatch |
41 | | -def bellman_ford_path(G, source, target, weight: str = "weight"): ... |
| 50 | +def bellman_ford_path(G, source, target, weight: str | _WeightFunction = "weight"): ... |
42 | 51 | @_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"): ... |
44 | 53 | @_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"): ... |
46 | 55 | @_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"): ... |
48 | 57 | @_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"): ... |
50 | 59 | @_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]: ... |
52 | 61 | @_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]: ... |
54 | 63 | @_dispatch |
55 | | -def goldberg_radzik(G, source, weight: str = "weight"): ... |
| 64 | +def goldberg_radzik(G, source, weight: str | _WeightFunction = "weight"): ... |
56 | 65 | @_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): ... |
58 | 67 | @_dispatch |
59 | | -def find_negative_cycle(G, source, weight: str = "weight"): ... |
| 68 | +def find_negative_cycle(G, source, weight: str | _WeightFunction = "weight"): ... |
60 | 69 | @_dispatch |
61 | | -def bidirectional_dijkstra(G, source, target, weight: str = "weight"): ... |
| 70 | +def bidirectional_dijkstra(G, source, target, weight: str | _WeightFunction = "weight"): ... |
62 | 71 | @_dispatch |
63 | | -def johnson(G, weight: str = "weight"): ... |
| 72 | +def johnson(G, weight: str | _WeightFunction = "weight"): ... |
0 commit comments