Fix Python 3.9 compatibility issues

Resolved startup errors:

1. Type hint compatibility:
   - Changed SkaterStatsDTO | GoalieStatsDTO to Union[SkaterStatsDTO, GoalieStatsDTO]
   - Python 3.9 does not support | operator for type unions

2. Yahoo Fantasy adapter import:
   - Made yfpy import lazy in get_fantasy_repository()
   - Prevents ModuleNotFoundError when yfpy not installed
   - Only loads Yahoo adapter when actually needed

3. Updated startup script for compatibility

The application now starts successfully on Python 3.9.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Michael Simard
2025-11-23 22:49:48 -06:00
parent c10fdd594d
commit ff0ca17b15
3 changed files with 23 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
"""Player Data Transfer Objects."""
from typing import Optional
from typing import Optional, Union
from pydantic import BaseModel
@@ -59,5 +59,5 @@ class PlayerWithStatsDTO(BaseModel):
"""Combined player information and statistics."""
player: PlayerDTO
stats: Optional[SkaterStatsDTO | GoalieStatsDTO]
stats: Optional[Union[SkaterStatsDTO, GoalieStatsDTO]]
stats_type: str # "skater", "goalie", or "none"

View File

@@ -3,7 +3,6 @@ from functools import lru_cache
from src.domain.repositories import PlayerRepository, TeamRepository, FantasyRepository
from src.infrastructure.adapters.nhl import NHLPlayerAdapter, NHLTeamAdapter
from src.infrastructure.adapters.yahoo_fantasy import YahooFantasyAdapter
from src.infrastructure.config import Settings, get_settings
@@ -40,6 +39,9 @@ def get_fantasy_repository() -> FantasyRepository:
This function can be modified to return different implementations
without changing any business logic or API code.
"""
# Lazy import to avoid requiring yfpy until actually needed
from src.infrastructure.adapters.yahoo_fantasy import YahooFantasyAdapter
settings = get_cached_settings()
return YahooFantasyAdapter(
consumer_key=settings.yahoo_consumer_key,

18
start_server.sh Executable file
View File

@@ -0,0 +1,18 @@
#!/bin/bash
# Startup script for Project Kempe Fantasy Hockey Backend
cd "$(dirname "$0")"
echo "=========================================="
echo "Project Kempe - Fantasy Hockey Backend"
echo "=========================================="
echo ""
echo "Starting FastAPI server..."
echo "Server will be available at: http://localhost:8000"
echo "API Documentation: http://localhost:8000/docs"
echo ""
echo "Press Ctrl+C to stop the server"
echo ""
# Start the server using python module
python3 -m uvicorn src.presentation.api.main:app --reload --host 0.0.0.0 --port 8000