From a3e5b284ce2d8de75f5ef7a40ee63beac8ee6d80 Mon Sep 17 00:00:00 2001 From: Chuck <33324927+ChuckBuilds@users.noreply.github.com> Date: Thu, 3 Sep 2026 12:59:20 -0400 Subject: [PATCH] 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 --- src/common/sports_shared.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/common/sports_shared.py b/src/common/sports_shared.py index 1148d354..f427817d 100644 --- a/src/common/sports_shared.py +++ b/src/common/sports_shared.py @@ -77,14 +77,11 @@ implementations, and is left for its own change. from __future__ import annotations import logging -import math import os import sys import time -from abc import abstractmethod from datetime import datetime, timedelta, timezone from typing import Any, ClassVar, Dict, List, Optional, Tuple -from zoneinfo import ZoneInfo import pytz import requests @@ -952,14 +949,16 @@ class SportsCoreSharedMixin: # not unique ("NEW" is both Newcastle and New Zealand), while the rest # match on abbreviation. Ask for the lineage's own matcher rather than # assuming, or this silently groups nothing and every slot goes empty. - team_in = getattr(self, "_team_in", None) - if callable(team_in): - def belongs(game, team): - return bool(team_in(game.get("home_id"), [team]) - or team_in(game.get("away_id"), [team])) - else: + matcher = getattr(self, "_team_in", None) + if not callable(matcher): + matcher = None # an is-None test narrows for static analysis + if matcher is None: def belongs(game, team): 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} for game in games: # already in kickoff order