Skip to content

[mypy] Type annotations for graphs/finding_bridges.py and graphs/random_graph_generator.py #5795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 8, 2021
8 changes: 7 additions & 1 deletion graphs/finding_bridges.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@ def dfs(at, parent, bridges, id):
# This edge is a back edge and cannot be a bridge
low[at] = min(low[at], low[to])

bridges = []
bridges: list[tuple[int, int]] = []
for i in range(n):
if not visited[i]:
dfs(i, -1, bridges, id)
return bridges


if __name__ == "__main__":
import doctest

doctest.testmod()
2 changes: 1 addition & 1 deletion graphs/random_graph_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def random_graph(
>>> random_graph(4, 0.5, True)
{0: [1], 1: [2, 3], 2: [3], 3: []}
"""
graph = {i: [] for i in range(vertices_number)}
graph: dict = {i: [] for i in range(vertices_number)}

# if probability is greater or equal than 1, then generate a complete graph
if probability >= 1:
Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
ignore_missing_imports = True
install_types = True
non_interactive = True
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)
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)