[Utils] Better error handling for humanize_list (#2597)

This commit is contained in:
Michael H 2019-04-22 22:34:38 -04:00 committed by GitHub
parent 2c8a425f87
commit 012d99c05c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -360,7 +360,10 @@ def humanize_list(items: Sequence[str]) -> str:
"""
if len(items) == 1:
return items[0]
return ", ".join(items[:-1]) + _(", and ") + items[-1]
try:
return ", ".join(items[:-1]) + _(", and ") + items[-1]
except IndexError:
raise IndexError("Cannot humanize empty sequence") from None
def format_perms_list(perms: discord.Permissions) -> str: