Skip to content

Commit

Permalink
Fix pre-commit errors
Browse files Browse the repository at this point in the history
  • Loading branch information
FPA-AkshayGollahalli committed Apr 22, 2023
1 parent ba6e627 commit 05289bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/humanize/lists.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"""Lists related humanization."""
from typing import AnyStr, List

__all__ = ["naturallist"]


def naturallist(items: List[AnyStr]) -> str:
"""Convert a list of items into a human-readable string with commas and 'and'
"""Natural list.
Convert a list of items into a human-readable string with commas and 'and'
Args:
items (list): A list of strings
Expand All @@ -18,10 +21,9 @@ def naturallist(items: List[AnyStr]) -> str:
>>> naturallist(["one"])
'one'
"""

if len(items) == 1:
return items[0]
return str(items[0])
elif len(items) == 2:
return f"{items[0]} and {items[1]}"
return f"{str(items[0])} and {str(items[1])}"
else:
return ", ".join(items[:-1]) + f" and {items[-1]}"
return ", ".join(str(item) for item in items[:-1]) + f" and {str(items[-1])}"
2 changes: 1 addition & 1 deletion tests/test_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
([[""]], ""),
],
)
def test_naturallist(test_args, expected):
def test_naturallist(test_args: list[str], expected: str) -> None:
assert humanize.naturallist(*test_args) == expected

0 comments on commit 05289bd

Please sign in to comment.