Skip to content

[mypy] Fix type annotations in graphs/boruvka.py #5794

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 3 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@

## Computer Vision
* [Cnn Classification](https://github.com/TheAlgorithms/Python/blob/master/computer_vision/cnn_classification.py)
* [Flip Augmentation](https://github.com/TheAlgorithms/Python/blob/master/computer_vision/flip_augmentation.py)
* [Harris Corner](https://github.com/TheAlgorithms/Python/blob/master/computer_vision/harris_corner.py)
* [Mean Threshold](https://github.com/TheAlgorithms/Python/blob/master/computer_vision/mean_threshold.py)
* [Mosaic Augmentation](https://github.com/TheAlgorithms/Python/blob/master/computer_vision/mosaic_augmentation.py)

## Conversions
* [Binary To Decimal](https://github.com/TheAlgorithms/Python/blob/master/conversions/binary_to_decimal.py)
Expand Down Expand Up @@ -297,8 +299,8 @@
* [Test Send File](https://github.com/TheAlgorithms/Python/blob/master/file_transfer/tests/test_send_file.py)

## Financial
* [Equated Monthly Installments](https://github.com/TheAlgorithms/Python/blob/master/financial/equated_monthly_installments.py)
* [Interest](https://github.com/TheAlgorithms/Python/blob/master/financial/interest.py)
* [EMI Calculation](https://github.com/TheAlgorithms/Python/blob/master/financial/equated_monthly_installments.py)

## Fractals
* [Julia Sets](https://github.com/TheAlgorithms/Python/blob/master/fractals/julia_sets.py)
Expand Down
8 changes: 5 additions & 3 deletions graphs/boruvka.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"""
from __future__ import annotations

from typing import Any


class Graph:
def __init__(self, num_of_nodes: int) -> None:
Expand Down Expand Up @@ -62,7 +64,7 @@ def set_component(self, u_node: int) -> None:
for k in self.m_component:
self.m_component[k] = self.find_component(k)

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

minimum_weight_edge: list[int] = [-1] * self.m_num_of_nodes
minimum_weight_edge: list[Any] = [-1] * self.m_num_of_nodes

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

for edge in minimum_weight_edge:
if edge != -1:
if isinstance(edge, list):
u, v, w = edge

u_component = self.m_component[u]
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/boruvka.py|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/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)