From f1c37e3ec3e2603850228c87a96c9a0ee8a25b2c Mon Sep 17 00:00:00 2001 From: Pedro Monteiro <83892026+peda-cos@users.noreply.github.com> Date: Sun, 11 Oct 2026 01:57:05 -0300 Subject: [PATCH] fix: honor empty-list contract for generator input make_linked_list declared the input as Iterable[int] but tested emptiness with truthiness, so an empty generator silently produced an empty LinkedList instead of raising. Materialize the iterable first and cover generator input with doctests. --- data_structures/linked_list/print_reverse.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/data_structures/linked_list/print_reverse.py b/data_structures/linked_list/print_reverse.py index a023745dee69..98c8b4e11505 100644 --- a/data_structures/linked_list/print_reverse.py +++ b/data_structures/linked_list/print_reverse.py @@ -98,7 +98,14 @@ def make_linked_list(elements_list: Iterable[int]) -> LinkedList: abc >>> make_linked_list([7, 25]) 7 -> 25 + >>> make_linked_list(x for x in [7, 25]) + 7 -> 25 + >>> make_linked_list(x for x in range(0)) + Traceback (most recent call last): + ... + Exception: The Elements List is empty """ + elements_list = list(elements_list) if not elements_list: raise Exception("The Elements List is empty")