From 663ae1bafc98badb45e0fddccd07f4daac772513 Mon Sep 17 00:00:00 2001 From: murari2401 Date: Thu, 26 Aug 2021 00:19:11 +0530 Subject: [PATCH 1/8] [mypy] Fix type annotations for backtracking/sudoku.py --- backtracking/sudoku.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backtracking/sudoku.py b/backtracking/sudoku.py index 593fa52d6d8a..0849d420ff19 100644 --- a/backtracking/sudoku.py +++ b/backtracking/sudoku.py @@ -1,7 +1,6 @@ """ Given a partially filled 9×9 2D array, the objective is to fill a 9×9 -square grid with digits numbered 1 to 9, so that every row, column, and -and each of the nine 3×3 sub-grids contains all of the digits. +square grid with digits numbered 1 to 9, so that every row, column, and each of the nine 3×3 sub-grids contains all of the digits. This can be solved using Backtracking and is similar to n-queens. We check to see if a cell is safe or not and recursively call the @@ -90,8 +89,9 @@ def sudoku(grid: Matrix) -> Optional[Matrix]: >>> sudoku(no_solution) is None True """ - if location := find_empty_location(grid): - row, column = location + if find_empty_location(grid)!=None: + #Assigning list values to row and column + row, column = find_empty_location(grid) else: # If the location is ``None``, then the grid is solved. return grid From 017e1b89603333770bc37d85a408bcc57d40d212 Mon Sep 17 00:00:00 2001 From: murari2401 Date: Thu, 26 Aug 2021 02:08:37 +0530 Subject: [PATCH 2/8] [mypy] Fix type annotations for graphics/vector3_for_2d_rendering.py --- graphics/vector3_for_2d_rendering.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index dfa22262a8d8..ca8a885159d9 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -97,6 +97,6 @@ def rotate( if __name__ == "__main__": import doctest - doctest.testmod() - print(f"{convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0) = }") - print(f"{rotate(1.0, 2.0, 3.0, 'y', 90.0) = }") + doctest.testmod(verbose=True) + print(f"convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0): {convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0)}") + print(f"rotate(1.0, 2.0, 3.0, 'y', 90.0): {rotate(1.0, 2.0, 3.0, 'y', 90.0)}") From 7383366bfcba866f16f559ff3cacaf73aa6e51c9 Mon Sep 17 00:00:00 2001 From: murari2401 Date: Thu, 26 Aug 2021 11:56:19 +0530 Subject: [PATCH 3/8] [mypy] Fix type annotations for maths/area.py --- maths/area.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/maths/area.py b/maths/area.py index 8689f323cc9a..f1660d0b4f53 100644 --- a/maths/area.py +++ b/maths/area.py @@ -275,14 +275,14 @@ def area_rhombus(diagonal_1: float, diagonal_2: float) -> float: doctest.testmod(verbose=True) # verbose so we can see methods missing tests print("[DEMO] Areas of various geometric shapes: \n") - print(f"Rectangle: {area_rectangle(10, 20) = }") - print(f"Square: {area_square(10) = }") - print(f"Triangle: {area_triangle(10, 10) = }") - print(f"Triangle: {area_triangle_three_sides(5, 12, 13) = }") - print(f"Parallelogram: {area_parallelogram(10, 20) = }") - print(f"Trapezium: {area_trapezium(10, 20, 30) = }") - print(f"Circle: {area_circle(20) = }") + print(f"Rectangle: {area_rectangle(10, 20)}") + print(f"Square: {area_square(10)}") + print(f"Triangle: {area_triangle(10, 10)}") + print(f"Triangle: {area_triangle_three_sides(5, 12, 13)}") + print(f"Parallelogram: {area_parallelogram(10, 20)}") + print(f"Trapezium: {area_trapezium(10, 20, 30)}") + print(f"Circle: {area_circle(20)}") print("\nSurface Areas of various geometric shapes: \n") - print(f"Cube: {surface_area_cube(20) = }") - print(f"Sphere: {surface_area_sphere(20) = }") - print(f"Rhombus: {area_rhombus(10, 20) = }") + print(f"Cube: {surface_area_cube(20)}") + print(f"Sphere: {surface_area_sphere(20)}") + print(f"Rhombus: {area_rhombus(10, 20)}") From 6d15c193642c0759e2c91db705259f224076e574 Mon Sep 17 00:00:00 2001 From: murari2401 Date: Thu, 26 Aug 2021 12:42:13 +0530 Subject: [PATCH 4/8] [mypy] Fix type annotations for maths/two_pointer.py --- maths/two_pointer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maths/two_pointer.py b/maths/two_pointer.py index ff234cddc9e4..e94556cd3040 100644 --- a/maths/two_pointer.py +++ b/maths/two_pointer.py @@ -57,5 +57,5 @@ def two_pointer(nums: list[int], target: int) -> list[int]: if __name__ == "__main__": import doctest - doctest.testmod() - print(f"{two_pointer([2, 7, 11, 15], 9) = }") + doctest.testmod(verbose=True) + print(f"two_pointer([2, 7, 11, 15], 9): {two_pointer([2, 7, 11, 15], 9)}") \ No newline at end of file From c4384601f443c303651f407efa0b59640d6d8163 Mon Sep 17 00:00:00 2001 From: murari2401 Date: Thu, 26 Aug 2021 12:51:46 +0530 Subject: [PATCH 5/8] [mypy] Fix type annotations for maths/two_sum.py --- maths/two_sum.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maths/two_sum.py b/maths/two_sum.py index 12ad332d6c4e..cb92e226dc90 100644 --- a/maths/two_sum.py +++ b/maths/two_sum.py @@ -43,5 +43,5 @@ def two_sum(nums: list[int], target: int) -> list[int]: if __name__ == "__main__": import doctest - doctest.testmod() - print(f"{two_sum([2, 7, 11, 15], 9) = }") + doctest.testmod(verbose=True) + print(f"two_sum([2, 7, 11, 15], 9): {two_sum([2, 7, 11, 15], 9)}") From 29380f59e475d6bf5e99b9c089d6a30a65d7312d Mon Sep 17 00:00:00 2001 From: murari2401 Date: Thu, 26 Aug 2021 14:50:50 +0530 Subject: [PATCH 6/8] [mypy] Fix type annotations for maths/ugly_numbers.py --- maths/ugly_numbers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/ugly_numbers.py b/maths/ugly_numbers.py index 4451a68cdaad..65cc8b2d3110 100644 --- a/maths/ugly_numbers.py +++ b/maths/ugly_numbers.py @@ -51,4 +51,4 @@ def ugly_numbers(n: int) -> int: from doctest import testmod testmod(verbose=True) - print(f"{ugly_numbers(200) = }") + print(f"ugly_numbers(200): {ugly_numbers(200)}") From aac34f9aedf78698021dc1b26e6395e0243a87fe Mon Sep 17 00:00:00 2001 From: murari2401 Date: Sat, 28 Aug 2021 13:32:37 +0530 Subject: [PATCH 7/8] [mypy] Fix type annotations for matrix/matrix_operation.py --- matrix/matrix_operation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/matrix/matrix_operation.py b/matrix/matrix_operation.py index dca01f9c3183..827a94b573c2 100644 --- a/matrix/matrix_operation.py +++ b/matrix/matrix_operation.py @@ -167,9 +167,9 @@ def main(): matrix_b = [[3, 4], [7, 4]] matrix_c = [[11, 12, 13, 14], [21, 22, 23, 24], [31, 32, 33, 34], [41, 42, 43, 44]] matrix_d = [[3, 0, 2], [2, 0, -2], [0, 1, 1]] - print(f"Add Operation, {add(matrix_a, matrix_b) = } \n") + print(f"Add Operation, {add(matrix_a, matrix_b)} \n") print( - f"Multiply Operation, {multiply(matrix_a, matrix_b) = } \n", + f"Multiply Operation, {multiply(matrix_a, matrix_b)} \n", ) print(f"Identity: {identity(5)}\n") print(f"Minor of {matrix_c} = {minor(matrix_c, 1, 2)} \n") @@ -180,5 +180,5 @@ def main(): if __name__ == "__main__": import doctest - doctest.testmod() + doctest.testmod(verbose=True) main() From 202a74bffb09fa1974cbae19a9d09720a84f933f Mon Sep 17 00:00:00 2001 From: murari2401 Date: Tue, 31 Aug 2021 14:36:24 +0530 Subject: [PATCH 8/8] [mypy] Fix type annotations for sorts/cocktail_shaker_sort.py sorts/insertion_sort.py --- sorts/cocktail_shaker_sort.py | 4 ++-- sorts/exchange_sort.py | 3 ++- sorts/insertion_sort.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sorts/cocktail_shaker_sort.py b/sorts/cocktail_shaker_sort.py index b738ff31d768..2a5bf6fd2dcb 100644 --- a/sorts/cocktail_shaker_sort.py +++ b/sorts/cocktail_shaker_sort.py @@ -40,7 +40,7 @@ def cocktail_shaker_sort(unsorted: list) -> list: if __name__ == "__main__": import doctest - doctest.testmod() + doctest.testmod(verbose=True) user_input = input("Enter numbers separated by a comma:\n").strip() unsorted = [int(item) for item in user_input.split(",")] - print(f"{cocktail_shaker_sort(unsorted) = }") + print(f"{cocktail_shaker_sort(unsorted)}") diff --git a/sorts/exchange_sort.py b/sorts/exchange_sort.py index 1ce78a9dc0cb..295b6e00a5c1 100644 --- a/sorts/exchange_sort.py +++ b/sorts/exchange_sort.py @@ -23,5 +23,6 @@ def exchange_sort(numbers: list[int]) -> list[int]: if __name__ == "__main__": user_input = input("Enter numbers separated by a comma:\n").strip() - unsorted = [int(item) for item in user_input.split(",")] + unsorted = list([int(item) for item in user_input.split(",")]) + list(unsorted) print(exchange_sort(unsorted)) diff --git a/sorts/insertion_sort.py b/sorts/insertion_sort.py index 6d5bb2b46013..bed4ff531518 100644 --- a/sorts/insertion_sort.py +++ b/sorts/insertion_sort.py @@ -53,8 +53,8 @@ def insertion_sort(collection: list) -> list: if __name__ == "__main__": from doctest import testmod - testmod() + testmod(verbose=True) user_input = input("Enter numbers separated by a comma:\n").strip() unsorted = [int(item) for item in user_input.split(",")] - print(f"{insertion_sort(unsorted) = }") + print(f"{insertion_sort(unsorted)}")