Address some pylance warnings.

This commit is contained in:
2025-04-23 14:15:39 -04:00
parent d38f56ff41
commit 4d96aebeb1
+14 -8
View File
@@ -34,20 +34,20 @@ VoteType = StrEnum("VoteType", ["COUNCIL", "DISCORDMANAGER", "CLANLEADER"])
PointType = StrEnum("PointType", ["CLAN", "EVENT"]) PointType = StrEnum("PointType", ["CLAN", "EVENT"])
def get_datetime(day: str) -> datetime: def get_datetime(month_day: str) -> datetime:
""" """
Takes in a string month and day and returns a datetime object of that Month/Day this year. Takes in a string month and day and returns a datetime object of that Month/Day this year.
Args: Args:
day (str): Month/Day in that format. month_day (str): Month/Day in that format.
Returns: Returns:
datetime: Datetime representation of Month/Day. datetime: Datetime representation of Month/Day.
""" """
today = datetime.now(tz=UTC).date() today = datetime.now(tz=UTC).date()
year = today.year year = today.year
month = int(day.split("/")[0]) month = int(month_day.split("/")[0])
day = int(day.split("/")[1]) day = int(month_day.split("/")[1])
# ensure that year rolls over if current month is December and the next month is less than 12. # ensure that year rolls over if current month is December and the next month is less than 12.
if today.month == calendar.DECEMBER and month < calendar.OCTOBER: if today.month == calendar.DECEMBER and month < calendar.OCTOBER:
@@ -66,7 +66,10 @@ def get_election_name() -> str:
Returns: Returns:
str: the name of the election cycle str: the name of the election cycle
""" """
cycle = get_active_election_cycle() if cycle := get_active_election_cycle() is None:
# undefined behavior
print("Did not find an active election cycle. Undefined behavior with return string.") # noqa: T201
return "No-active-election-cycle"
current_cycle = settings.election_cycles[cycle] current_cycle = settings.election_cycles[cycle]
return f"vote-{get_datetime(current_cycle.term_start).year}-{current_cycle.name}" return f"vote-{get_datetime(current_cycle.term_start).year}-{current_cycle.name}"
@@ -78,13 +81,16 @@ def get_quarter_name() -> str:
Returns: Returns:
str: the name of the cycle. str: the name of the cycle.
""" """
cycle = get_quarter_cycle() if cycle := get_quarter_cycle() is None:
# undefined behavior
print("Did not find a quarter cycle. Undefined behavior with return string.") # noqa: T201
return "no-quarter-cycle"
current_cycle = settings.election_cycles[cycle] current_cycle = settings.election_cycles[cycle]
return f"{get_datetime(current_cycle.term_start).year}-{current_cycle.name}" return f"{get_datetime(current_cycle.term_start).year}-{current_cycle.name}"
def get_active_election_cycle() -> int: def get_active_election_cycle() -> int | None:
""" """
Returns index for active election. An election is considered active between the election start and the term start. Returns index for active election. An election is considered active between the election start and the term start.
@@ -104,7 +110,7 @@ def get_active_election_cycle() -> int:
return get_quarter_cycle() return get_quarter_cycle()
def get_quarter_cycle() -> int: def get_quarter_cycle() -> int | None:
""" """
Returns the index for the current cycle/quarter. Defined as between term start and end. Returns the index for the current cycle/quarter. Defined as between term start and end.