refactor: review remaining justified lazy imports for dependency injection #57
Labels
No Label
ai-changes-requested
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
in-next-release
status/in-progress
status/pr-open
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/major-domo-v2#57
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
A full codebase audit identified ~50 lazy imports. ~42 unnecessary ones have been moved to top-level imports. The remaining 8 locations have legitimate reasons (circular imports, init-order, optional deps) but most could be eliminated with proper dependency injection.
Remaining Lazy Imports to Review
Circular Import Avoidance — DI Candidates
models/player.py:92—from models.team import TeaminsidePlayer.from_api_data()player ↔ teammodels reference each othermodels/team.py:154, 175, 198—from services.team_service import team_service(×3)major_league_affiliate(),minor_league_affiliate(),injured_list_affiliate()team_serviceas a parameter to these methods instead of importing the singletonutils/decorators.py:128-129—from services.league_service import league_serviceandfrom views.embeds import EmbedTemplaterequires_draft_perioddecorator's wrapper functionleague_serviceas a decorator parameter or use a registry patternutils/permissions.py:51—from services.team_service import team_serviceget_user_team()team_serviceas a parameterservices/decision_service.py:103—from services.player_service import player_servicefind_winning_losing_pitchers()player_servicevia constructorIntentional Architectural Patterns — Keep As-Is
commands/draft/admin.py:41—from tasks.draft_monitor import setup_draft_monitor_ensure_monitor_running()bot.py:114-130— 17 command package imports inside_load_command_packages()bot.py:194-211— 4 task/service imports inside_setup_background_tasks()Not a Lazy Import
utils/cache.py:10-15—import redis.asyncioin try/except at module levelservices/player_service.py:16andviews/players.py:16-18—TYPE_CHECKINGguardsSuggested Approach
Items 1-5 are all candidates for dependency injection refactoring. The most impactful would be:
models/team.py(3 lazy imports) — passteam_serviceto affiliate lookup methodsservices/decision_service.py— injectplayer_servicevia constructorutils/permissions.py— acceptteam_serviceas parameter toget_user_team()Items 6-8 should remain as-is — they serve important architectural purposes.