[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
This commit is contained in:
Rohan R Bharadwaj 2021-11-08 22:48:33 +05:30 committed by GitHub
parent ac4bdfd66d
commit a8aeabdf18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View File

@ -93,8 +93,14 @@ def compute_bridges(graph: dict[int, list[int]]) -> list[tuple[int, int]]:
# This edge is a back edge and cannot be a bridge # This edge is a back edge and cannot be a bridge
low[at] = min(low[at], low[to]) low[at] = min(low[at], low[to])
bridges = [] bridges: list[tuple[int, int]] = []
for i in range(n): for i in range(n):
if not visited[i]: if not visited[i]:
dfs(i, -1, bridges, id) dfs(i, -1, bridges, id)
return bridges return bridges
if __name__ == "__main__":
import doctest
doctest.testmod()

View File

@ -26,7 +26,7 @@ def random_graph(
>>> random_graph(4, 0.5, True) >>> random_graph(4, 0.5, True)
{0: [1], 1: [2, 3], 2: [3], 3: []} {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 is greater or equal than 1, then generate a complete graph
if probability >= 1: if probability >= 1:

View File

@ -2,4 +2,4 @@
ignore_missing_imports = True ignore_missing_imports = True
install_types = True install_types = True
non_interactive = 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)