From 438f337dad9c4b175d8209caf4e40c007cf03e81 Mon Sep 17 00:00:00 2001 From: jabrailkhalil Date: Tue, 8 Sep 2026 14:26:17 +0300 Subject: [PATCH] fix(sorts): validate bucket count in bucket_sort --- sorts/bucket_sort.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sorts/bucket_sort.py b/sorts/bucket_sort.py index 893c7ff3a23a..c83470636083 100644 --- a/sorts/bucket_sort.py +++ b/sorts/bucket_sort.py @@ -31,7 +31,9 @@ from __future__ import annotations -def bucket_sort(my_list: list, bucket_count: int = 10) -> list: +def bucket_sort( + my_list: list[int | float], bucket_count: int = 10 +) -> list[int | float]: """ >>> data = [-1, 2, -5, 0] >>> bucket_sort(data) == sorted(data) @@ -65,6 +67,10 @@ def bucket_sort(my_list: list, bucket_count: int = 10) -> list: True >>> bucket_sort([1]) == [1] True + >>> bucket_sort([1, 2, 3], 2.5) + Traceback (most recent call last): + ... + TypeError: bucket_count must be an integer >>> data = [-1.1, -1.5, -3.4, 2.5, 3.6, -3.3] >>> bucket_sort(data) == sorted(data) True @@ -73,6 +79,8 @@ def bucket_sort(my_list: list, bucket_count: int = 10) -> list: True """ + if not isinstance(bucket_count, int): + raise TypeError("bucket_count must be an integer") if len(my_list) == 0 or bucket_count <= 0: return []