fix behavior with two items
This commit is contained in:
parent
0bde1a034b
commit
7b2cb92b60
2 changed files with 2 additions and 1 deletions
|
|
@ -93,6 +93,7 @@ class TestListToString(TestCase):
|
||||||
'"1", "2" and "3"', utils.list_to_string([1, 2, 3], endsep="and", addquote=True)
|
'"1", "2" and "3"', utils.list_to_string([1, 2, 3], endsep="and", addquote=True)
|
||||||
)
|
)
|
||||||
self.assertEqual("1 and 2", utils.list_to_string([1, 2]))
|
self.assertEqual("1 and 2", utils.list_to_string([1, 2]))
|
||||||
|
self.assertEqual("1, 2", utils.list_to_string([1, 2], endsep=","))
|
||||||
|
|
||||||
|
|
||||||
class TestMLen(TestCase):
|
class TestMLen(TestCase):
|
||||||
|
|
|
||||||
|
|
@ -448,7 +448,7 @@ def iter_to_str(iterable, sep=",", endsep=", and", addquote=False):
|
||||||
iterable = tuple(str(val) for val in iterable)
|
iterable = tuple(str(val) for val in iterable)
|
||||||
|
|
||||||
if endsep:
|
if endsep:
|
||||||
if endsep.startswith(sep):
|
if endsep.startswith(sep) and endsep != sep:
|
||||||
# oxford comma alternative
|
# oxford comma alternative
|
||||||
endsep = endsep[1:] if len_iter < 3 else endsep
|
endsep = endsep[1:] if len_iter < 3 else endsep
|
||||||
elif endsep[0] not in punctuation:
|
elif endsep[0] not in punctuation:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue