1
- from _typeshed import Incomplete
2
- from collections .abc import Callable , Generator
1
+ from collections .abc import Generator
3
2
from typing import overload
4
3
4
+ from networkx .algorithms .shortest_paths .weighted import _WeightFunc
5
5
from networkx .classes .graph import Graph , _Node
6
6
from networkx .utils .backends import _dispatchable
7
7
@@ -17,55 +17,129 @@ __all__ = [
17
17
18
18
@_dispatchable
19
19
def has_path (G : Graph [_Node ], source : _Node , target : _Node ) -> bool : ...
20
- @overload
20
+ @overload # both source and target are specified => (s -> t)
21
21
def shortest_path (
22
22
G : Graph [_Node ],
23
- source : _Node | None = None ,
24
- target : _Node | None = None ,
25
- weight : str | Callable [..., Incomplete ] | None = None ,
23
+ source : _Node ,
24
+ target : _Node ,
25
+ weight : str | _WeightFunc [ _Node ] | None = None ,
26
26
method : str | None = "dijkstra" ,
27
+ * ,
28
+ backend : str | None = None ,
29
+ ** backend_kwargs ,
27
30
) -> list [_Node ]: ...
28
- @overload
31
+ @overload # only source is specified => {t1: (s -> t), t2: (s -> t), ...}
29
32
def shortest_path (
30
33
G : Graph [_Node ],
31
- source : _Node | None = None ,
32
- target : _Node | None = None ,
33
- weight : str | Callable [..., Incomplete ] | None = None ,
34
+ source : _Node ,
35
+ target : None = None ,
36
+ weight : str | _WeightFunc [ _Node ] | None = None ,
34
37
method : str | None = "dijkstra" ,
38
+ * ,
39
+ backend : str | None = None ,
40
+ ** backend_kwargs ,
35
41
) -> dict [_Node , list [_Node ]]: ...
36
- @overload
42
+ @overload # only target is specified (positional) => {s1: (s1 -> t), s2: (s2 -> t), ...}
37
43
def shortest_path (
38
44
G : Graph [_Node ],
39
- source : _Node | None = None ,
40
- target : _Node | None = None ,
41
- weight : str | Callable [..., Incomplete ] | None = None ,
45
+ source : None ,
46
+ target : _Node ,
47
+ weight : str | _WeightFunc [ _Node ] | None = None ,
42
48
method : str | None = "dijkstra" ,
49
+ * ,
50
+ backend : str | None = None ,
51
+ ** backend_kwargs ,
43
52
) -> dict [_Node , list [_Node ]]: ...
44
- @_dispatchable
53
+ @overload # only target is specified (keyword) => {s1: (s1 -> t), s2: (s2 -> t), ...}
54
+ def shortest_path (
55
+ G : Graph [_Node ],
56
+ source : None = None ,
57
+ * ,
58
+ target : _Node ,
59
+ weight : str | _WeightFunc [_Node ] | None = None ,
60
+ method : str | None = "dijkstra" ,
61
+ backend : str | None = None ,
62
+ ** backend_kwargs ,
63
+ ) -> dict [_Node , list [_Node ]]: ...
64
+ @overload
65
+ def shortest_path ( # source and target are not specified => generator of (t, {s1: (s1 -> t), s2: (s2 -> t), ...})
66
+ G : Graph [_Node ],
67
+ source : None = None ,
68
+ target : None = None ,
69
+ weight : str | _WeightFunc [_Node ] | None = None ,
70
+ method : str | None = "dijkstra" ,
71
+ * ,
72
+ backend : str | None = None ,
73
+ ** backend_kwargs ,
74
+ ) -> Generator [tuple [_Node , dict [str , list [_Node ]]]]: ...
75
+ @overload # both source and target are specified => len(s -> t)
45
76
def shortest_path_length (
46
77
G : Graph [_Node ],
47
- source : _Node | None = None ,
48
- target : _Node | None = None ,
49
- weight : str | Callable [..., Incomplete ] | None = None ,
78
+ source : _Node ,
79
+ target : _Node ,
80
+ weight : str | _WeightFunc [ _Node ] | None = None ,
50
81
method : str | None = "dijkstra" ,
51
- ): ...
52
- @_dispatchable
53
- def average_shortest_path_length (
54
- G : Graph [_Node ], weight : str | Callable [..., Incomplete ] | None = None , method : str | None = None
55
- ): ...
56
- @_dispatchable
57
- def all_shortest_paths (
82
+ * ,
83
+ backend : str | None = None ,
84
+ ** backend_kwargs ,
85
+ ) -> float : ...
86
+ @overload # only source is specified => {t1: len(s -> t1), t2: len(s -> t2), ...}
87
+ def shortest_path_length (
58
88
G : Graph [_Node ],
59
89
source : _Node ,
90
+ target : None = None ,
91
+ weight : str | _WeightFunc [_Node ] | None = None ,
92
+ method : str | None = "dijkstra" ,
93
+ * ,
94
+ backend : str | None = None ,
95
+ ** backend_kwargs ,
96
+ ) -> dict [_Node , float ]: ...
97
+ @overload # only target is specified (positional) => {s1: len(s1 -> t), s2: len(s2 -> t), ...}
98
+ def shortest_path_length (
99
+ G : Graph [_Node ],
100
+ source : None ,
101
+ target : _Node ,
102
+ weight : str | _WeightFunc [_Node ] | None = None ,
103
+ method : str | None = "dijkstra" ,
104
+ * ,
105
+ backend : str | None = None ,
106
+ ** backend_kwargs ,
107
+ ) -> dict [_Node , float ]: ...
108
+ @overload # only target is specified (keyword) => {s1: len(s1 -> t), s2: len(s2 -> t), ...}
109
+ def shortest_path_length (
110
+ G : Graph [_Node ],
111
+ source : None = None ,
112
+ * ,
60
113
target : _Node ,
61
- weight : str | Callable [..., Incomplete ] | None = None ,
114
+ weight : str | _WeightFunc [_Node ] | None = None ,
115
+ method : str | None = "dijkstra" ,
116
+ backend : str | None = None ,
117
+ ** backend_kwargs ,
118
+ ) -> dict [_Node , float ]: ...
119
+ @overload
120
+ def shortest_path_length ( # source and target are not specified => generator of (t, {s1: len(s1 -> t), s2: len(s2 -> t), ...})
121
+ G : Graph [_Node ],
122
+ source : None = None ,
123
+ target : None = None ,
124
+ weight : str | _WeightFunc [_Node ] | None = None ,
62
125
method : str | None = "dijkstra" ,
63
- ) -> Generator [list [_Node ], None , None ]: ...
126
+ * ,
127
+ backend : str | None = None ,
128
+ ** backend_kwargs ,
129
+ ) -> Generator [tuple [_Node , dict [_Node , float ]]]: ...
130
+ @_dispatchable
131
+ def average_shortest_path_length (
132
+ G : Graph [_Node ], weight : str | _WeightFunc [_Node ] | None = None , method : str | None = None
133
+ ) -> float : ...
134
+ @_dispatchable
135
+ def all_shortest_paths (
136
+ G : Graph [_Node ], source : _Node , target : _Node , weight : str | _WeightFunc [_Node ] | None = None , method : str | None = "dijkstra"
137
+ ) -> Generator [list [_Node ]]: ...
64
138
@_dispatchable
65
139
def single_source_all_shortest_paths (
66
- G , source , weight = None , method = "dijkstra"
67
- ) -> Generator [tuple [Incomplete , list [list [Incomplete ]]]]: ...
140
+ G : Graph [ _Node ] , source : _Node , weight : str | _WeightFunc [ _Node ] | None = None , method : str | None = "dijkstra"
141
+ ) -> Generator [tuple [_Node , list [list [_Node ]]]]: ...
68
142
@_dispatchable
69
143
def all_pairs_all_shortest_paths (
70
- G , weight = None , method = "dijkstra"
71
- ) -> Generator [tuple [Incomplete , dict [Incomplete , Incomplete ]]]: ...
144
+ G : Graph [ _Node ] , weight : str | _WeightFunc [ _Node ] | None = None , method : str | None = "dijkstra"
145
+ ) -> Generator [tuple [_Node , dict [_Node , list [ list [ _Node ]] ]]]: ...
0 commit comments