From a74debb82dba47ac843ac6b769d8d6d50f3e2f30 Mon Sep 17 00:00:00 2001 From: kwzrd Date: Wed, 1 Apr 2020 09:40:30 +0200 Subject: Deseasonify: implement __str__ for Month enum This way, we can standardize the way Months are shown to both the user and the developer. Note that if passing a Month member to an f-string, the `!s` format code must be specified to ensure our __str__ is used. Co-authored-by: MarkKoz --- bot/utils/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'bot/utils/__init__.py') diff --git a/bot/utils/__init__.py b/bot/utils/__init__.py index 69bff4de..35ef0a7b 100644 --- a/bot/utils/__init__.py +++ b/bot/utils/__init__.py @@ -3,7 +3,7 @@ import contextlib import re import string from datetime import datetime -from typing import List +from typing import Iterable, List import discord from discord.ext.commands import BadArgument, Context @@ -12,6 +12,11 @@ from bot.constants import Client, Month from bot.utils.pagination import LinePaginator +def human_months(months: Iterable[Month]) -> str: + """Build a comma separated list of `months`.""" + return ", ".join(str(m) for m in months) + + def resolve_current_month() -> Month: """ Determine current month w.r.t. `Client.month_override` env var. -- cgit v1.2.3