From ac4bdfd66dbbd4c7c92c73d894469aa4a5c3e5ab Mon Sep 17 00:00:00 2001 From: Dylan Buchi Date: Mon, 8 Nov 2021 10:47:09 -0300 Subject: [PATCH] [mypy] Fix type annotations in `graphs/boruvka.py` (#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> --- DIRECTORY.md | 4 +++- graphs/boruvka.py | 8 +++++--- mypy.ini | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index f515277f4..228d95472 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -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) @@ -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) diff --git a/graphs/boruvka.py b/graphs/boruvka.py index eea0b0009..2715a3085 100644 --- a/graphs/boruvka.py +++ b/graphs/boruvka.py @@ -26,6 +26,8 @@ """ from __future__ import annotations +from typing import Any + class Graph: def __init__(self, num_of_nodes: int) -> None: @@ -62,7 +64,7 @@ class Graph: 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""" @@ -84,7 +86,7 @@ class Graph: 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): @@ -119,7 +121,7 @@ class Graph: 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] diff --git a/mypy.ini b/mypy.ini index df69fa841..16ca60c4d 100644 --- a/mypy.ini +++ b/mypy.ini @@ -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)