Skip to content

Commit a8aeabd

Browse files
[mypy] Type annotations for graphs/finding_bridges.py and graphs/random_graph_generator.py (#5795)
* [mypy] Annotate `graphs/finding_bridges.py` * Remove from excluded in `mypy.ini` * Add doctest.testmod() * psf/black formatting * Annotations for `graphs/random_graph_generator.py` * Remove from excluded in `mypy.ini` * Resolve merge conflict * Resolve merge conflict * Update mypy.ini * Update mypy.ini * Remove from excluded
1 parent ac4bdfd commit a8aeabd

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Diff for: graphs/finding_bridges.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,14 @@ def dfs(at, parent, bridges, id):
9393
# This edge is a back edge and cannot be a bridge
9494
low[at] = min(low[at], low[to])
9595

96-
bridges = []
96+
bridges: list[tuple[int, int]] = []
9797
for i in range(n):
9898
if not visited[i]:
9999
dfs(i, -1, bridges, id)
100100
return bridges
101+
102+
103+
if __name__ == "__main__":
104+
import doctest
105+
106+
doctest.testmod()

Diff for: graphs/random_graph_generator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def random_graph(
2626
>>> random_graph(4, 0.5, True)
2727
{0: [1], 1: [2, 3], 2: [3], 3: []}
2828
"""
29-
graph = {i: [] for i in range(vertices_number)}
29+
graph: dict = {i: [] for i in range(vertices_number)}
3030

3131
# if probability is greater or equal than 1, then generate a complete graph
3232
if probability >= 1:

Diff for: mypy.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
ignore_missing_imports = True
33
install_types = True
44
non_interactive = True
5-
exclude = (graphs/breadth_first_search.py|graphs/breadth_first_search_2.py|graphs/check_cycle.py|graphs/finding_bridges.py|graphs/greedy_min_vertex_cover.py|graphs/random_graph_generator.py|matrix_operation.py|other/least_recently_used.py|other/lfu_cache.py|other/lru_cache.py|searches/simulated_annealing.py|searches/ternary_search.py)
5+
exclude = (graphs/breadth_first_search.py|graphs/breadth_first_search_2.py|graphs/check_cycle.py|graphs/greedy_min_vertex_cover.py|matrix_operation.py|other/least_recently_used.py|other/lfu_cache.py|other/lru_cache.py|searches/simulated_annealing.py|searches/ternary_search.py)

0 commit comments

Comments
 (0)