Skip to content

[mypy]Correction of all errors in the sorts directory #4224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sorts/bucket_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

Source: https://en.wikipedia.org/wiki/Bucket_sort
"""
from typing import List


def bucket_sort(my_list: list) -> list:
Expand All @@ -51,7 +52,7 @@ def bucket_sort(my_list: list) -> list:
return []
min_value, max_value = min(my_list), max(my_list)
bucket_count = int(max_value - min_value) + 1
buckets = [[] for _ in range(bucket_count)]
buckets: List[list] = [[] for _ in range(bucket_count)]

for i in range(len(my_list)):
buckets[(int(my_list[i] - min_value) // bucket_count)].append(my_list[i])
Expand Down
3 changes: 2 additions & 1 deletion sorts/cocktail_shaker_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def cocktail_shaker_sort(unsorted: list) -> list:
swapped = True

if not swapped:
return unsorted
break
return unsorted


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion sorts/patience_sort.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from bisect import bisect_left
from functools import total_ordering
from heapq import merge
from typing import List

"""
A pure Python implementation of the patience sort algorithm
Expand Down Expand Up @@ -43,7 +44,7 @@ def patience_sort(collection: list) -> list:
>>> patience_sort([-3, -17, -48])
[-48, -17, -3]
"""
stacks = []
stacks: List[Stack] = []
# sort into stacks
for element in collection:
new_stacks = Stack([element])
Expand Down
2 changes: 1 addition & 1 deletion sorts/radix_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def radix_sort(list_of_ints: List[int]) -> List[int]:
max_digit = max(list_of_ints)
while placement <= max_digit:
# declare and initialize empty buckets
buckets = [list() for _ in range(RADIX)]
buckets: List[list] = [list() for _ in range(RADIX)]
# split list_of_ints between the buckets
for i in list_of_ints:
tmp = int((i / placement) % RADIX)
Expand Down
8 changes: 5 additions & 3 deletions sorts/recursive_insertion_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from __future__ import annotations

from typing import List


def rec_insertion_sort(collection: list, n: int):
"""
Expand Down Expand Up @@ -70,6 +72,6 @@ def insert_next(collection: list, index: int):

if __name__ == "__main__":
numbers = input("Enter integers separated by spaces: ")
numbers = [int(num) for num in numbers.split()]
rec_insertion_sort(numbers, len(numbers))
print(numbers)
number_list: List[int] = [int(num) for num in numbers.split()]
rec_insertion_sort(number_list, len(number_list))
print(number_list)