Skip to content

Commit 7342b33

Browse files
authored
Fix mypy erros at strongly connected component (TheAlgorithms#4558)
1 parent bc09ba9 commit 7342b33

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

graphs/strongly_connected_components.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
test_graph_2 = {0: [1, 2, 3], 1: [2], 2: [0], 3: [4], 4: [5], 5: [3]}
1111

1212

13-
def topology_sort(graph: dict, vert: int, visited: list) -> list:
13+
def topology_sort(
14+
graph: dict[int, list[int]], vert: int, visited: list[bool]
15+
) -> list[int]:
1416
"""
1517
Use depth first search to sort graph
1618
At this time graph is the same as input
@@ -32,7 +34,9 @@ def topology_sort(graph: dict, vert: int, visited: list) -> list:
3234
return order
3335

3436

35-
def find_components(reversed_graph: dict, vert: int, visited: list) -> list:
37+
def find_components(
38+
reversed_graph: dict[int, list[int]], vert: int, visited: list[bool]
39+
) -> list[int]:
3640
"""
3741
Use depth first search to find strongliy connected
3842
vertices. Now graph is reversed
@@ -52,7 +56,7 @@ def find_components(reversed_graph: dict, vert: int, visited: list) -> list:
5256
return component
5357

5458

55-
def strongly_connected_components(graph: dict) -> list:
59+
def strongly_connected_components(graph: dict[int, list[int]]) -> list[list[int]]:
5660
"""
5761
This function takes graph as a parameter
5862
and then returns the list of strongly connected components
@@ -63,7 +67,7 @@ def strongly_connected_components(graph: dict) -> list:
6367
"""
6468

6569
visited = len(graph) * [False]
66-
reversed_graph = {vert: [] for vert in range(len(graph))}
70+
reversed_graph: dict[int, list[int]] = {vert: [] for vert in range(len(graph))}
6771

6872
for vert, neighbours in graph.items():
6973
for neighbour in neighbours:
@@ -84,9 +88,3 @@ def strongly_connected_components(graph: dict) -> list:
8488
components_list.append(component)
8589

8690
return components_list
87-
88-
89-
if __name__ == "__main__":
90-
import doctest
91-
92-
doctest.testmod()

0 commit comments

Comments
 (0)