[mypy] Fix type annotations in `graphs/boruvka.py` (#5794) · zinating/algorithms-python@ac4bdfd · GitHub
Skip to content

Commit ac4bdfd

Browse files
dylanbuchigithub-actions
andauthored
[mypy] Fix type annotations in graphs/boruvka.py (TheAlgorithms#5794)
* Fix type annotations in boruvka.py * Remove graphs/boruvka.py| * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 2f6a7ae commit ac4bdfd

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

DIRECTORY.md

Lines changed: 3 additions & 1 deletion

graphs/boruvka.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
"""
2727
from __future__ import annotations
2828

29+
from typing import Any
30+
2931

3032
class Graph:
3133
def __init__(self, num_of_nodes: int) -> None:
@@ -62,7 +64,7 @@ def set_component(self, u_node: int) -> None:
6264
for k in self.m_component:
6365
self.m_component[k] = self.find_component(k)
6466

65-
def union(self, component_size: list, u_node: int, v_node: int) -> None:
67+
def union(self, component_size: list[int], u_node: int, v_node: int) -> None:
6668
"""Union finds the roots of components for two nodes, compares the components
6769
in terms of size, and attaches the smaller one to the larger one to form
6870
single component"""
@@ -84,7 +86,7 @@ def boruvka(self) -> None:
8486
component_size = []
8587
mst_weight = 0
8688

87-
minimum_weight_edge: list[int] = [-1] * self.m_num_of_nodes
89+
minimum_weight_edge: list[Any] = [-1] * self.m_num_of_nodes
8890

8991
# A list of components (initialized to all of the nodes)
9092
for node in range(self.m_num_of_nodes):
@@ -119,7 +121,7 @@ def boruvka(self) -> None:
119121
minimum_weight_edge[component] = [u, v, w]
120122

121123
for edge in minimum_weight_edge:
122-
if edge != -1:
124+
if isinstance(edge, list):
123125
u, v, w = edge
124126

125127
u_component = self.m_component[u]

mypy.ini

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)