From 2cafc344b60b16935d2f7c76e694401993bea167 Mon Sep 17 00:00:00 2001 From: ahmadalguydi Date: Sun, 2 Aug 2026 21:27:28 +0300 Subject: [PATCH] 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 []