Skip to content

Commit 4cf7f6c

Browse files
authored
Fix ruff linting
1 parent 27c8aff commit 4cf7f6c

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

sorts/quick_sort_with_tests.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
from typing import List, Optional
2-
3-
4-
def quick_sort(arr: List[int]) -> List[int]:
1+
def quick_sort(arr: list[int]) -> list[int]:
52
"""
63
Classic quick sort implementation using list comprehensions.
74
85
Args:
9-
arr (List[int]): List of integers to sort.
6+
arr (list[int]): List of integers to sort.
107
118
Returns:
12-
List[int]: New sorted list.
9+
list[int]: New sorted list.
1310
"""
1411
if len(arr) <= 1:
1512
return arr
@@ -21,19 +18,17 @@ def quick_sort(arr: List[int]) -> List[int]:
2118
return quick_sort(left) + middle + quick_sort(right)
2219

2320

24-
def quick_sort_3way(
25-
arr: List[int], low: int = 0, high: Optional[int] = None
26-
) -> List[int]:
21+
def quick_sort_3way(arr: list[int], low: int = 0, high: int | None = None) -> list[int]:
2722
"""
2823
In-place 3-way partitioning quick sort.
2924
3025
Args:
31-
arr (List[int]): List of integers to sort.
26+
arr (list[int]): List of integers to sort.
3227
low (int): Starting index of the sublist to sort.
33-
high (Optional[int]): Ending index of the sublist to sort.
28+
high (int | None): Ending index of the sublist to sort.
3429
3530
Returns:
36-
List[int]: The same list sorted in-place.
31+
list[int]: The same list sorted in-place.
3732
"""
3833
if high is None:
3934
high = len(arr) - 1
@@ -73,12 +68,8 @@ def test_quick_sorts():
7368
]
7469

7570
for i, (input_arr, expected) in enumerate(test_cases):
76-
assert quick_sort(input_arr) == expected, (
77-
f"quick_sort failed on test case {i + 1}"
78-
)
79-
assert quick_sort_3way(input_arr.copy()) == expected, (
80-
f"quick_sort_3way failed on test case {i + 1}"
81-
)
71+
assert quick_sort(input_arr) == expected, f"quick_sort failed on test case {i + 1}"
72+
assert quick_sort_3way(input_arr.copy()) == expected, f"quick_sort_3way failed on test case {i + 1}"
8273

8374
print("All tests passed!")
8475

0 commit comments

Comments
 (0)