From 959507901ac8f10cd605c51c305d13b27d105536 Mon Sep 17 00:00:00 2001 From: algobytewise Date: Tue, 23 Mar 2021 21:21:50 +0530 Subject: [PATCH] [mypy] fix small folders (#4292) * add final else-statement * fix file_transfer * fix quantum folder * fix divide_and_conquer-folder * Update build.yml * updating DIRECTORY.md * Update ripple_adder_classic.py * Update .github/workflows/build.yml * removed imports from typing * removed conversion to string * Revert "removed conversion to string" This reverts commit 2f7c4731d103f24c73fb98c9a6898525998774c5. * implemented suggested changes * Update receive_file.py Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Christian Clauss --- .github/workflows/build.yml | 7 ++++++- divide_and_conquer/max_difference_pair.py | 5 +---- divide_and_conquer/strassen_matrix_multiplication.py | 2 +- electronics/electric_power.py | 2 ++ electronics/ohms_law.py | 2 ++ file_transfer/receive_file.py | 2 +- file_transfer/send_file.py | 2 +- quantum/ripple_adder_classic.py | 2 +- 8 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c85b82330..74b885b90 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,13 +30,18 @@ jobs: cellular_automata compression computer_vision + divide_and_conquer + electronics + file_transfer fractals fuzzy_logic genetic_algorithm geodesy knapsack networking_flow - scheduling sorts + quantum + scheduling + sorts - name: Run tests run: pytest --doctest-modules --ignore=project_euler/ --ignore=scripts/ --cov-report=term-missing:skip-covered --cov=. . - if: ${{ success() }} diff --git a/divide_and_conquer/max_difference_pair.py b/divide_and_conquer/max_difference_pair.py index b976aca43..ffc4b76a7 100644 --- a/divide_and_conquer/max_difference_pair.py +++ b/divide_and_conquer/max_difference_pair.py @@ -1,7 +1,4 @@ -from typing import List - - -def max_difference(a: List[int]) -> (int, int): +def max_difference(a: list[int]) -> tuple[int, int]: """ We are given an array A[1..n] of integers, n >= 1. We want to find a pair of indices (i, j) such that diff --git a/divide_and_conquer/strassen_matrix_multiplication.py b/divide_and_conquer/strassen_matrix_multiplication.py index 29a174dae..ca10e04ab 100644 --- a/divide_and_conquer/strassen_matrix_multiplication.py +++ b/divide_and_conquer/strassen_matrix_multiplication.py @@ -121,7 +121,7 @@ def strassen(matrix1: list, matrix2: list) -> list: dimension2 = matrix_dimensions(matrix2) if dimension1[0] == dimension1[1] and dimension2[0] == dimension2[1]: - return matrix1, matrix2 + return [matrix1, matrix2] maximum = max(max(dimension1), max(dimension2)) maxim = int(math.pow(2, math.ceil(math.log2(maximum)))) diff --git a/electronics/electric_power.py b/electronics/electric_power.py index 8f0293bd2..e4e685bbd 100644 --- a/electronics/electric_power.py +++ b/electronics/electric_power.py @@ -42,6 +42,8 @@ def electric_power(voltage: float, current: float, power: float) -> Tuple: return result("current", power / voltage) elif power == 0: return result("power", float(round(abs(voltage * current), 2))) + else: + raise ValueError("Exactly one argument must be 0") if __name__ == "__main__": diff --git a/electronics/ohms_law.py b/electronics/ohms_law.py index c53619a10..41bffa9f8 100644 --- a/electronics/ohms_law.py +++ b/electronics/ohms_law.py @@ -32,6 +32,8 @@ def ohms_law(voltage: float, current: float, resistance: float) -> Dict[str, flo return {"current": voltage / resistance} elif resistance == 0: return {"resistance": voltage / current} + else: + raise ValueError("Exactly one argument must be 0") if __name__ == "__main__": diff --git a/file_transfer/receive_file.py b/file_transfer/receive_file.py index cfba6ed88..37a503036 100644 --- a/file_transfer/receive_file.py +++ b/file_transfer/receive_file.py @@ -13,7 +13,7 @@ if __name__ == "__main__": print("Receiving data...") while True: data = sock.recv(1024) - print(f"data={data}") + print(f"{data = }") if not data: break out_file.write(data) # Write data to a file diff --git a/file_transfer/send_file.py b/file_transfer/send_file.py index 5b53471df..1c56e48f4 100644 --- a/file_transfer/send_file.py +++ b/file_transfer/send_file.py @@ -13,7 +13,7 @@ def send_file(filename: str = "mytext.txt", testing: bool = False) -> None: conn, addr = sock.accept() # Establish connection with client. print(f"Got connection from {addr}") data = conn.recv(1024) - print(f"Server received {data}") + print(f"Server received: {data = }") with open(filename, "rb") as in_file: data = in_file.read(1024) diff --git a/quantum/ripple_adder_classic.py b/quantum/ripple_adder_classic.py index f5b0a980c..dc0c2103b 100644 --- a/quantum/ripple_adder_classic.py +++ b/quantum/ripple_adder_classic.py @@ -6,7 +6,7 @@ from qiskit import Aer, QuantumCircuit, execute from qiskit.providers import BaseBackend -def store_two_classics(val1: int, val2: int) -> (QuantumCircuit, str, str): +def store_two_classics(val1: int, val2: int) -> tuple[QuantumCircuit, str, str]: """ Generates a Quantum Circuit which stores two classical integers Returns the circuit and binary representation of the integers