mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-10-18 04:49:13 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user