Skip to content

Commit 0cd69ae

Browse files
typing: define SortFunction protocol for benchmark sorts
1 parent 3935d28 commit 0cd69ae

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎sorts/benchmark_sorts.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import random
2222
import sys
23-
from collections.abc import Callable, Sequence
23+
from collections.abc import Sequence
2424
from itertools import pairwise
2525
from timeit import timeit
2626
from typing import Protocol
@@ -37,8 +37,13 @@
3737
from sorts.shell_sort import shell_sort
3838
from sorts.tim_sort import tim_sort
3939

40+
41+
class SortFunction(Protocol):
42+
def __call__[T](self, collection: list[T], /) -> Sequence[T]: ...
43+
44+
4045
# name -> callable. Every callable accepts a list and returns the sorted list.
41-
SORTS: dict[str, Callable[[list[int]], Sequence[int]]] = {
46+
SORTS: dict[str, SortFunction] = {
4247
"bubble_sort": bubble_sort_iterative,
4348
"cocktail_shaker_sort": cocktail_shaker_sort,
4449
"comb_sort": comb_sort,

0 commit comments

Comments
 (0)