fix(sports): drop three unused imports and let the matcher narrow

Codacy flagged five issues on this file.

Three are unused imports: math, abc.abstractmethod and zoneinfo.ZoneInfo.
Nothing in the module references any of them -- the timezone work goes through
pytz, and the @abstractmethod mention in the module docstring describes the
two stubs that deliberately stayed behind in each plugin, not anything
declared here. pyflakes agrees; all three are removed.

The other two are "team_in is not callable" on the round-robin favourite
matcher. That call is already guarded by callable(), so it cannot raise at
runtime, but callable() is not a narrowing construct a static analyser
follows: the name still carries the None from getattr's default. Normalising a
non-callable to None and branching on `is None` gives the analyser a test it
does understand, and keeps the guard.

Behaviour is unchanged. _round_robin_favorites has no test coverage, so I
exercised it directly on both paths -- a host with _team_in (id matching, the
NRL case) and one without (abbreviation matching) -- across limits 1 to 4, and
the selections are identical before and after. A host whose _team_in is
present but not callable still falls back to abbreviation matching rather than
raising.

test/test_sports_shared.py: 27 passed. The 9 collection errors under
`pytest test/ -k sport` reproduce identically on the unmodified branch and are
not from this change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Chuck
2026-09-03 12:59:20 -04:00
co-authored by Claude Opus 5
parent 3fa69645f7
commit a3e5b284ce
+8 -9
View File
@@ -77,14 +77,11 @@ implementations, and is left for its own change.
from __future__ import annotations from __future__ import annotations
import logging import logging
import math
import os import os
import sys import sys
import time import time
from abc import abstractmethod
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from typing import Any, ClassVar, Dict, List, Optional, Tuple from typing import Any, ClassVar, Dict, List, Optional, Tuple
from zoneinfo import ZoneInfo
import pytz import pytz
import requests import requests
@@ -952,14 +949,16 @@ class SportsCoreSharedMixin:
# not unique ("NEW" is both Newcastle and New Zealand), while the rest # not unique ("NEW" is both Newcastle and New Zealand), while the rest
# match on abbreviation. Ask for the lineage's own matcher rather than # match on abbreviation. Ask for the lineage's own matcher rather than
# assuming, or this silently groups nothing and every slot goes empty. # assuming, or this silently groups nothing and every slot goes empty.
team_in = getattr(self, "_team_in", None) matcher = getattr(self, "_team_in", None)
if callable(team_in): if not callable(matcher):
def belongs(game, team): matcher = None # an is-None test narrows for static analysis
return bool(team_in(game.get("home_id"), [team]) if matcher is None:
or team_in(game.get("away_id"), [team]))
else:
def belongs(game, team): def belongs(game, team):
return team in (game.get("home_abbr"), game.get("away_abbr")) return team in (game.get("home_abbr"), game.get("away_abbr"))
else:
def belongs(game, team):
return bool(matcher(game.get("home_id"), [team])
or matcher(game.get("away_id"), [team]))
queues = {team: [] for team in wanted} queues = {team: [] for team in wanted}
for game in games: # already in kickoff order for game in games: # already in kickoff order