Skip to content

Commit 7000653

Browse files
committed
fix: use PEP 695 type params, remove TypeVar import
1 parent 82cb9c7 commit 7000653

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

sorts/quick_sort.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@
1111
from __future__ import annotations
1212

1313
from random import randrange
14-
from typing import Any, Protocol, TypeVar
14+
from typing import Any, Protocol
1515

1616

1717
class Comparable(Protocol):
1818
def __lt__(self, other: Any, /) -> bool: ...
1919

2020

21-
T = TypeVar("T", bound=Comparable)
22-
23-
24-
def quick_sort(collection: list[T]) -> list[T]:
21+
def quick_sort[T: Comparable](collection: list[T]) -> list[T]:
2522
"""A pure Python implementation of quicksort algorithm.
2623
2724
:param collection: a mutable collection of comparable items
@@ -43,7 +40,6 @@ def quick_sort(collection: list[T]) -> list[T]:
4340
>>> quick_sort(["z", "a", "m"]) == sorted(["z", "a", "m"])
4441
True
4542
"""
46-
# Base case: if the collection has 0 or 1 elements, it is already sorted
4743
if len(collection) < 2:
4844
return collection
4945
pivot_index = randrange(len(collection))

0 commit comments

Comments
 (0)