File tree Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change
1
+ """Lists related humanization."""
1
2
from typing import AnyStr , List
2
3
3
4
__all__ = ["naturallist" ]
4
5
5
6
6
7
def naturallist (items : List [AnyStr ]) -> str :
7
- """Convert a list of items into a human-readable string with commas and 'and'
8
+ """Natural list.
9
+
10
+ Convert a list of items into a human-readable string with commas and 'and'
8
11
9
12
Args:
10
13
items (list): A list of strings
@@ -18,10 +21,9 @@ def naturallist(items: List[AnyStr]) -> str:
18
21
>>> naturallist(["one"])
19
22
'one'
20
23
"""
21
-
22
24
if len (items ) == 1 :
23
- return items [0 ]
25
+ return str ( items [0 ])
24
26
elif len (items ) == 2 :
25
- return f"{ items [0 ]} and { items [1 ]} "
27
+ return f"{ str ( items [0 ]) } and { str ( items [1 ]) } "
26
28
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 ]) } "
Original file line number Diff line number Diff line change 13
13
([["" ]], "" ),
14
14
],
15
15
)
16
- def test_naturallist (test_args , expected ) :
16
+ def test_naturallist (test_args : list [ str ] , expected : str ) -> None :
17
17
assert humanize .naturallist (* test_args ) == expected
You can’t perform that action at this time.
0 commit comments