From 310bb4cadc2411612aa774aaa1743ef63de8b33b Mon Sep 17 00:00:00 2001 From: changsheng Date: Mon, 31 Aug 2026 01:00:32 +0800 Subject: [PATCH] Add type hints to pancake_sort function (#14745) * Add type hints to pancake_sort function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Use modern list[int] type hint instead of deprecated typing.List * Update pancake_sort to use Sequence and TypeVar Refactor pancake_sort function to accept any sequence type. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Make pancake_sort generic with type parameter T --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: changsheng Co-authored-by: Christian Clauss --- sorts/pancake_sort.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sorts/pancake_sort.py b/sorts/pancake_sort.py index e5d600738435..7fa4c02e981f 100644 --- a/sorts/pancake_sort.py +++ b/sorts/pancake_sort.py @@ -8,8 +8,13 @@ python pancake_sort.py """ +from collections.abc import Sequence +from typing import TypeVar -def pancake_sort(arr): +T = TypeVar("T") + + +def pancake_sort[T](arr: Sequence[T]) -> list[T]: """Sort Array with Pancake Sort. :param arr: Collection containing comparable items :return: Collection ordered in ascending order of items