From 08d4d226d797c94254f53be0c71d3304ea093bd4 Mon Sep 17 00:00:00 2001 From: Meysam Date: Sun, 17 Oct 2021 19:26:12 +0300 Subject: [PATCH] [mypy] Fix type annotations for graphs/boruvka (#4867) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: type annotations for pypi 🏷️ Fixes #4052 * updating DIRECTORY.md * apply suggestions from code review Co-authored-by: Christian Clauss Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Christian Clauss --- graphs/boruvka.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/graphs/boruvka.py b/graphs/boruvka.py index 3fa5c6fd2..eea0b0009 100644 --- a/graphs/boruvka.py +++ b/graphs/boruvka.py @@ -24,6 +24,7 @@ Details: https://en.wikipedia.org/wiki/Bor%C5%AFvka%27s_algorithm """ +from __future__ import annotations class Graph: @@ -39,8 +40,8 @@ class Graph: """ self.m_num_of_nodes = num_of_nodes - self.m_edges = [] - self.m_component = {} + self.m_edges: list[list[int]] = [] + self.m_component: dict[int, int] = {} def add_edge(self, u_node: int, v_node: int, weight: int) -> None: """Adds an edge in the format [first, second, edge weight] to graph.""" @@ -83,7 +84,7 @@ class Graph: component_size = [] mst_weight = 0 - minimum_weight_edge = [-1] * self.m_num_of_nodes + minimum_weight_edge: list[int] = [-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):