diff --git a/src/humanize/lists.py b/src/humanize/lists.py index 543a32f..525f0e3 100644 --- a/src/humanize/lists.py +++ b/src/humanize/lists.py @@ -28,6 +28,8 @@ def natural_list(items: list[Any]) -> str: Returns: str: A string with commas and 'and' in the right places. """ + if not items: + return "" if len(items) == 1: return str(items[0]) elif len(items) == 2: diff --git a/tests/test_lists.py b/tests/test_lists.py index a39d344..cc514f3 100644 --- a/tests/test_lists.py +++ b/tests/test_lists.py @@ -12,6 +12,7 @@ ([["one", "two", "three"]], "one, two and three"), ([["one", "two"]], "one and two"), ([["one"]], "one"), + ([[]], ""), ([[""]], ""), ([[1, 2, 3]], "1, 2 and 3"), ([[1, "two"]], "1 and two"),