Skip to content

Commit 14d76fb

Browse files
Fix pre-commit errors
1 parent ba6e627 commit 14d76fb

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/humanize/lists.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
from typing import AnyStr, List
1+
"""Lists related humanization."""
2+
from typing import Any, List
23

34
__all__ = ["naturallist"]
45

56

6-
def naturallist(items: List[AnyStr]) -> str:
7-
"""Convert a list of items into a human-readable string with commas and 'and'
7+
def naturallist(items: List[Any]) -> str:
8+
"""Natural list.
9+
10+
Convert a list of items into a human-readable string with commas and 'and'
811
912
Args:
1013
items (list): A list of strings
@@ -18,10 +21,9 @@ def naturallist(items: List[AnyStr]) -> str:
1821
>>> naturallist(["one"])
1922
'one'
2023
"""
21-
2224
if len(items) == 1:
23-
return items[0]
25+
return str(items[0])
2426
elif len(items) == 2:
25-
return f"{items[0]} and {items[1]}"
27+
return f"{str(items[0])} and {str(items[1])}"
2628
else:
27-
return ", ".join(items[:-1]) + f" and {items[-1]}"
29+
return ", ".join(str(item) for item in items[:-1]) + f" and {str(items[-1])}"

tests/test_lists.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
([["one", "two"]], "one and two"),
1212
([["one"]], "one"),
1313
([[""]], ""),
14+
([[1, 2, 3]], "1, 2 and 3"),
15+
([[1, "two"]], "1 and two"),
1416
],
1517
)
16-
def test_naturallist(test_args, expected):
18+
def test_naturallist(
19+
test_args: list[str] | list[int] | list[str | int], expected: str
20+
) -> None:
1721
assert humanize.naturallist(*test_args) == expected

0 commit comments

Comments
 (0)