From e7eed79b4d39ae5591e459563e3f02bd7a79bdfe Mon Sep 17 00:00:00 2001 From: agessaman Date: Thu, 1 Jan 2026 22:04:48 -0800 Subject: [PATCH] docs: Add `__init__` docstrings and refine type hints for client and command initializers. --- modules/clients/espn_client.py | 9 ++++++++- modules/clients/thesportsdb_client.py | 9 ++++++++- modules/commands/sports_command.py | 18 +++++++++++++----- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/modules/clients/espn_client.py b/modules/clients/espn_client.py index 5ebdbc8..aec73be 100644 --- a/modules/clients/espn_client.py +++ b/modules/clients/espn_client.py @@ -10,7 +10,14 @@ class ESPNClient: BASE_URL = "http://site.api.espn.com/apis/site/v2/sports" - def __init__(self, logger=None, timeout: int = 10, session: Optional[aiohttp.ClientSession] = None): + def __init__(self, logger: Optional[logging.Logger] = None, timeout: int = 10, session: Optional[aiohttp.ClientSession] = None): + """Initialize the ESPN API client. + + Args: + logger: Logger instance for error and info logging. If None, creates a default logger. + timeout: Request timeout in seconds (default: 10) + session: Optional existing aiohttp session to reuse. If None, creates new sessions as needed. + """ self.logger = logger or logging.getLogger(__name__) self.timeout = aiohttp.ClientTimeout(total=timeout) self.session = session diff --git a/modules/clients/thesportsdb_client.py b/modules/clients/thesportsdb_client.py index 8fc1da8..1b8a0d7 100644 --- a/modules/clients/thesportsdb_client.py +++ b/modules/clients/thesportsdb_client.py @@ -15,7 +15,14 @@ class TheSportsDBClient: BASE_URL = "https://www.thesportsdb.com/api/v1/json" FREE_API_KEY = "123" # Free public API key - def __init__(self, logger=None, timeout: int = 10, session: Optional[aiohttp.ClientSession] = None): + def __init__(self, logger: Optional[logging.Logger] = None, timeout: int = 10, session: Optional[aiohttp.ClientSession] = None): + """Initialize the TheSportsDB API client with rate limiting. + + Args: + logger: Logger instance for error and info logging. If None, creates a default logger. + timeout: Request timeout in seconds (default: 10) + session: Optional existing aiohttp session to reuse. If None, creates new sessions as needed. + """ self.logger = logger or logging.getLogger(__name__) self.timeout = aiohttp.ClientTimeout(total=timeout) self.session = session diff --git a/modules/commands/sports_command.py b/modules/commands/sports_command.py index 34d348a..d93fe7b 100644 --- a/modules/commands/sports_command.py +++ b/modules/commands/sports_command.py @@ -20,7 +20,7 @@ Team IDs should be periodically verified, especially after: """ from datetime import datetime, timezone -from typing import List, Dict, Optional +from typing import List, Dict, Optional, TYPE_CHECKING from .base_command import BaseCommand from ..models import MeshMessage from ..clients.espn_client import ESPNClient @@ -29,6 +29,9 @@ from ..clients.sports_mappings import ( SPORT_EMOJIS, TEAM_MAPPINGS, LEAGUE_MAPPINGS ) +if TYPE_CHECKING: + from ..core import MeshCoreBot + class SportsCommand(BaseCommand): """Handles sports commands with ESPN API integration""" @@ -47,15 +50,20 @@ class SportsCommand(BaseCommand): # TheSportsDB client for leagues not supported by ESPN thesportsdb_client: Optional[TheSportsDBClient] = None - - def __init__(self, bot): + + def __init__(self, bot: "MeshCoreBot"): + """Initialize the sports command with API clients and configuration. + + Args: + bot: The MeshCoreBot instance that owns this command. + """ super().__init__(bot) self.url_timeout = 10 # seconds - + # Initialize API clients self.espn_client = ESPNClient(logger=self.logger, timeout=self.url_timeout) self.thesportsdb_client = TheSportsDBClient(logger=self.logger) - + # Load default teams from config self.default_teams = self.load_default_teams() # Note: allowed_channels is now loaded by BaseCommand from config