From 20e98fcded341d5aef6dfdfc5cdac431a55252bd Mon Sep 17 00:00:00 2001 From: Hasenn Date: Sun, 13 Sep 2020 10:11:27 +0200 Subject: [PATCH] Fix some warnings from LGTM (#2420) * fix assignment of a variable to itself * Fix unnecessary 'else' clause in loop * formatting and redundant reasignment fix * mark unreachable code with a TODO comment * fix variable defined multiple times * fix static method without static decorator * revert unintended autoformatting Co-authored-by: Christian Clauss * revert autoformatting issue * applied black autoformatting Co-authored-by: Christian Clauss --- ciphers/enigma_machine2.py | 1 - graphs/directed_and_undirected_(weighted)_graph.py | 3 +++ graphs/minimum_spanning_tree_boruvka.py | 1 + maths/chudnovsky_algorithm.py | 1 - other/triplet_sum.py | 3 +-- scheduling/shortest_job_first.py | 6 ++++-- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ciphers/enigma_machine2.py b/ciphers/enigma_machine2.py index 0fbe97284..4344db005 100644 --- a/ciphers/enigma_machine2.py +++ b/ciphers/enigma_machine2.py @@ -218,7 +218,6 @@ def enigma( rotorpos1 -= 1 rotorpos2 -= 1 rotorpos3 -= 1 - plugboard = plugboard result = [] diff --git a/graphs/directed_and_undirected_(weighted)_graph.py b/graphs/directed_and_undirected_(weighted)_graph.py index 61e196adf..5cfa9e13e 100644 --- a/graphs/directed_and_undirected_(weighted)_graph.py +++ b/graphs/directed_and_undirected_(weighted)_graph.py @@ -226,6 +226,7 @@ class DirectedGraph: break else: return True + # TODO:The following code is unreachable. anticipating_nodes.add(stack[len_stack_minus_one]) len_stack_minus_one -= 1 if visited.count(node[1]) < 1: @@ -453,6 +454,8 @@ class Graph: break else: return True + # TODO: the following code is unreachable + # is this meant to be called in the else ? anticipating_nodes.add(stack[len_stack_minus_one]) len_stack_minus_one -= 1 if visited.count(node[1]) < 1: diff --git a/graphs/minimum_spanning_tree_boruvka.py b/graphs/minimum_spanning_tree_boruvka.py index f65aa7cef..3b05f94b5 100644 --- a/graphs/minimum_spanning_tree_boruvka.py +++ b/graphs/minimum_spanning_tree_boruvka.py @@ -146,6 +146,7 @@ class Graph: self.parent[root2] = root1 return root1 + @staticmethod def boruvka_mst(graph): """ Implementation of Boruvka's algorithm diff --git a/maths/chudnovsky_algorithm.py b/maths/chudnovsky_algorithm.py index fb188cd6a..aaee74628 100644 --- a/maths/chudnovsky_algorithm.py +++ b/maths/chudnovsky_algorithm.py @@ -44,7 +44,6 @@ def pi(precision: int) -> str: getcontext().prec = precision num_iterations = ceil(precision / 14) constant_term = 426880 * Decimal(10005).sqrt() - multinomial_term = 1 exponential_term = 1 linear_term = 13591409 partial_sum = Decimal(linear_term) diff --git a/other/triplet_sum.py b/other/triplet_sum.py index 247e3bb16..25fed5d54 100644 --- a/other/triplet_sum.py +++ b/other/triplet_sum.py @@ -61,8 +61,7 @@ def triplet_sum2(arr: List[int], target: int) -> Tuple[int, int, int]: left += 1 elif arr[i] + arr[left] + arr[right] > target: right -= 1 - else: - return (0, 0, 0) + return (0, 0, 0) def solution_times() -> Tuple[float, float]: diff --git a/scheduling/shortest_job_first.py b/scheduling/shortest_job_first.py index 6a2fdeeec..ecb6e01fd 100644 --- a/scheduling/shortest_job_first.py +++ b/scheduling/shortest_job_first.py @@ -11,7 +11,6 @@ import pandas as pd def calculate_waitingtime( arrival_time: List[int], burst_time: List[int], no_of_processes: int ) -> List[int]: - """ Calculate the waiting time of each processes Return: list of waiting times. @@ -126,13 +125,16 @@ if __name__ == "__main__": for i in range(no_of_processes): print("Enter the arrival time and brust time for process:--" + str(i + 1)) arrival_time[i], burst_time[i] = map(int, input().split()) + waiting_time = calculate_waitingtime(arrival_time, burst_time, no_of_processes) + bt = burst_time n = no_of_processes wt = waiting_time turn_around_time = calculate_turnaroundtime(bt, n, wt) + calculate_average_times(waiting_time, turn_around_time, no_of_processes) - processes = list(range(1, no_of_processes + 1)) + fcfs = pd.DataFrame( list(zip(processes, burst_time, arrival_time, waiting_time, turn_around_time)), columns=[