From 0118f453af9f14fb9f6044a95861cf3e7fe69d6e Mon Sep 17 00:00:00 2001 From: shriya-97 Date: Wed, 30 Sep 2026 19:17:41 +0530 Subject: [PATCH 1/6] code: add modern list type hint and annotations to double_linear_search_recursion --- searches/double_linear_search_recursion.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/searches/double_linear_search_recursion.py b/searches/double_linear_search_recursion.py index 1c483e974ca7..a4f129ed5f5f 100644 --- a/searches/double_linear_search_recursion.py +++ b/searches/double_linear_search_recursion.py @@ -1,4 +1,5 @@ -def search(list_data: list, key: int, left: int = 0, right: int = 0) -> int: +from __future__ import annotations +def search(list_data: list[int], key: int, left: int = 0, right: int = 0) -> int: """ Iterate through the array to find the index of key using recursion. :param list_data: the list to be searched From 32e1ee46e60bc2e43def8ae81114d8c43252407e Mon Sep 17 00:00:00 2001 From: shriya-97 Date: Sat, 3 Oct 2026 15:46:01 +0530 Subject: [PATCH 2/6] code: update list type hints to generic Any per code review --- searches/double_linear_search_recursion.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/searches/double_linear_search_recursion.py b/searches/double_linear_search_recursion.py index a4f129ed5f5f..b4bb513fb5a2 100644 --- a/searches/double_linear_search_recursion.py +++ b/searches/double_linear_search_recursion.py @@ -1,5 +1,5 @@ -from __future__ import annotations -def search(list_data: list[int], key: int, left: int = 0, right: int = 0) -> int: +from typing import Any +def search(list_data: list[Any], key: Any, left: int = 0, right: int = 0) -> int: """ Iterate through the array to find the index of key using recursion. :param list_data: the list to be searched From 6005d07def24d3d019361ede4ea77390ebdeb823 Mon Sep 17 00:00:00 2001 From: shriya-97 Date: Sun, 4 Oct 2026 10:40:22 +0530 Subject: [PATCH 3/6] code: Add comparable type and person doctests per maintainer review --- searches/double_linear_search_recursion.py | 29 ++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/searches/double_linear_search_recursion.py b/searches/double_linear_search_recursion.py index b4bb513fb5a2..01a409d0a1b9 100644 --- a/searches/double_linear_search_recursion.py +++ b/searches/double_linear_search_recursion.py @@ -1,5 +1,26 @@ -from typing import Any -def search(list_data: list[Any], key: Any, left: int = 0, right: int = 0) -> int: +from __future__ import annotations + +from dataclasses import dataclass +from typing import Protocol, TypeVar + + +class Comparable(Protocol): + def __gt__(self, other: Comparable) -> bool: + ... + + def __eq__(self, other: object) -> bool: + ... + + +T = TypeVar("T", bound=Comparable) + + +@dataclass +class Person: + first_name: str + + +def search(list_data: list[T], key: T, left: int = 0, right: int = 0) -> int: """ Iterate through the array to find the index of key using recursion. :param list_data: the list to be searched @@ -18,6 +39,10 @@ def search(list_data: list[Any], key: Any, left: int = 0, right: int = 0) -> int 0 >>> search([], 1) -1 + >>> search([Person("Al"), Person("Bob"), Person("Carl")], Person("Bob")) + 1 + >>> search([Person("Al"), Person("Bob"), Person("Carl")], "Bob") + -1 """ right = right or len(list_data) - 1 if left > right: From 37e4cbb537a4382682f16d9a5a267328caa0bc4f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 4 Oct 2026 05:35:44 +0000 Subject: [PATCH 4/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- searches/double_linear_search_recursion.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/searches/double_linear_search_recursion.py b/searches/double_linear_search_recursion.py index 01a409d0a1b9..58f972d19d73 100644 --- a/searches/double_linear_search_recursion.py +++ b/searches/double_linear_search_recursion.py @@ -5,11 +5,9 @@ class Comparable(Protocol): - def __gt__(self, other: Comparable) -> bool: - ... + def __gt__(self, other: Comparable) -> bool: ... - def __eq__(self, other: object) -> bool: - ... + def __eq__(self, other: object) -> bool: ... T = TypeVar("T", bound=Comparable) From 2e0b3c457f0079593a136af106d078405857ac7a Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 4 Oct 2026 07:18:31 -1000 Subject: [PATCH 5/6] Apply batched suggestions from code review Co-authored-by: Christian Clauss --- searches/double_linear_search_recursion.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/searches/double_linear_search_recursion.py b/searches/double_linear_search_recursion.py index 58f972d19d73..abc24b1a133f 100644 --- a/searches/double_linear_search_recursion.py +++ b/searches/double_linear_search_recursion.py @@ -1,16 +1,10 @@ -from __future__ import annotations - from dataclasses import dataclass -from typing import Protocol, TypeVar +from typing import Protocol class Comparable(Protocol): - def __gt__(self, other: Comparable) -> bool: ... - def __eq__(self, other: object) -> bool: ... - - -T = TypeVar("T", bound=Comparable) + def __gt__(self, other: Comparable) -> bool: ... @dataclass @@ -18,7 +12,7 @@ class Person: first_name: str -def search(list_data: list[T], key: T, left: int = 0, right: int = 0) -> int: +def search[T: Comparable](list_data: list[T], key: T, left: int = 0, right: int = 0) -> int: """ Iterate through the array to find the index of key using recursion. :param list_data: the list to be searched From 8cf28bbe847b637e63287ac95d0ff49e54530ebd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 4 Oct 2026 17:19:46 +0000 Subject: [PATCH 6/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- searches/double_linear_search_recursion.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/searches/double_linear_search_recursion.py b/searches/double_linear_search_recursion.py index abc24b1a133f..3c70c6d897ac 100644 --- a/searches/double_linear_search_recursion.py +++ b/searches/double_linear_search_recursion.py @@ -12,7 +12,9 @@ class Person: first_name: str -def search[T: Comparable](list_data: list[T], key: T, left: int = 0, right: int = 0) -> int: +def search[T: Comparable]( + list_data: list[T], key: T, left: int = 0, right: int = 0 +) -> int: """ Iterate through the array to find the index of key using recursion. :param list_data: the list to be searched