From 2cafc344b60b16935d2f7c76e694401993bea167 Mon Sep 17 00:00:00 2001 From: ahmadalguydi Date: Sun, 2 Aug 2026 21:27:28 +0300 Subject: [PATCH 1/2] fix: reject non-integer bucket counts Signed-off-by: ahmadalguydi --- sorts/bucket_sort.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sorts/bucket_sort.py b/sorts/bucket_sort.py index 893c7ff3a23a..627ac161de9a 100644 --- a/sorts/bucket_sort.py +++ b/sorts/bucket_sort.py @@ -63,6 +63,9 @@ def bucket_sort(my_list: list, bucket_count: int = 10) -> list: >>> data = [5.5, 2.2, -1.1, 3.3, 0.0] >>> bucket_sort(data) == sorted(data) True + >>> bucket_sort(data, 2.5) + Traceback (most recent call last): + TypeError: bucket_count must be an integer >>> bucket_sort([1]) == [1] True >>> data = [-1.1, -1.5, -3.4, 2.5, 3.6, -3.3] @@ -73,6 +76,9 @@ def bucket_sort(my_list: list, bucket_count: int = 10) -> list: True """ + if not isinstance(bucket_count, int) or isinstance(bucket_count, bool): + raise TypeError("bucket_count must be an integer") + if len(my_list) == 0 or bucket_count <= 0: return [] From fb068675a4a3a20943e8e3ae698f6dba6f362278 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 13 Sep 2026 13:30:52 +0200 Subject: [PATCH 2/2] Update bucket_sort.py --- sorts/bucket_sort.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sorts/bucket_sort.py b/sorts/bucket_sort.py index f15ceba8d8e7..4dba0cc22d0d 100644 --- a/sorts/bucket_sort.py +++ b/sorts/bucket_sort.py @@ -88,7 +88,6 @@ def bucket_sort( if not isinstance(bucket_count, (bool, int)): raise TypeError("bucket_count must be an integer") - if not my_list or bucket_count <= 0: return []