From 0cd69ae473eccfe1e89cf8df6967594300b4c5f7 Mon Sep 17 00:00:00 2001 From: satyaharendrarushidayaka-sudo Date: Mon, 12 Oct 2026 16:30:14 +0530 Subject: [PATCH] typing: define SortFunction protocol for benchmark sorts --- sorts/benchmark_sorts.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sorts/benchmark_sorts.py b/sorts/benchmark_sorts.py index 72b6b487e1a9..0035e75065c0 100644 --- a/sorts/benchmark_sorts.py +++ b/sorts/benchmark_sorts.py @@ -20,7 +20,7 @@ import random import sys -from collections.abc import Callable, Sequence +from collections.abc import Sequence from itertools import pairwise from timeit import timeit from typing import Protocol @@ -37,8 +37,13 @@ from sorts.shell_sort import shell_sort from sorts.tim_sort import tim_sort + +class SortFunction(Protocol): + def __call__[T](self, collection: list[T], /) -> Sequence[T]: ... + + # name -> callable. Every callable accepts a list and returns the sorted list. -SORTS: dict[str, Callable[[list[int]], Sequence[int]]] = { +SORTS: dict[str, SortFunction] = { "bubble_sort": bubble_sort_iterative, "cocktail_shaker_sort": cocktail_shaker_sort, "comb_sort": comb_sort,