Skip to content

Commit 08d4d22

Browse files
meysam81github-actionscclauss
authored
[mypy] Fix type annotations for graphs/boruvka (TheAlgorithms#4867)
* fix: type annotations for pypi 🏷️ Fixes TheAlgorithms#4052 * updating DIRECTORY.md * apply suggestions from code review Co-authored-by: Christian Clauss <[email protected]> Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Christian Clauss <[email protected]>
1 parent 4bf2eed commit 08d4d22

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Diff for: graphs/boruvka.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
2525
Details: https://en.wikipedia.org/wiki/Bor%C5%AFvka%27s_algorithm
2626
"""
27+
from __future__ import annotations
2728

2829

2930
class Graph:
@@ -39,8 +40,8 @@ def __init__(self, num_of_nodes: int) -> None:
3940
"""
4041

4142
self.m_num_of_nodes = num_of_nodes
42-
self.m_edges = []
43-
self.m_component = {}
43+
self.m_edges: list[list[int]] = []
44+
self.m_component: dict[int, int] = {}
4445

4546
def add_edge(self, u_node: int, v_node: int, weight: int) -> None:
4647
"""Adds an edge in the format [first, second, edge weight] to graph."""
@@ -83,7 +84,7 @@ def boruvka(self) -> None:
8384
component_size = []
8485
mst_weight = 0
8586

86-
minimum_weight_edge = [-1] * self.m_num_of_nodes
87+
minimum_weight_edge: list[int] = [-1] * self.m_num_of_nodes
8788

8889
# A list of components (initialized to all of the nodes)
8990
for node in range(self.m_num_of_nodes):

0 commit comments

Comments
 (0)