24 lines
1.3 KiB
Markdown
24 lines
1.3 KiB
Markdown
---
|
|
id: b235f924-b532-40cd-be39-4fb765938add
|
|
type: solution
|
|
title: "Break circular imports by extracting shared models to models.py"
|
|
tags: [python, circular-imports, architecture, refactoring, paper-dynasty]
|
|
importance: 0.8
|
|
confidence: 0.8
|
|
created: "2026-02-25T22:44:18.326495+00:00"
|
|
updated: "2026-02-25T22:44:42.053812+00:00"
|
|
relations:
|
|
- target: 9c7873fa-2c4e-4058-a315-cefb3c02788a
|
|
type: BUILDS_ON
|
|
direction: outgoing
|
|
strength: 0.8
|
|
edge_id: 45342806-cdc6-478e-aa38-4294045aafe8
|
|
- target: 30d490e1-5ae8-4db8-a238-8973a09f99d1
|
|
type: BUILDS_ON
|
|
direction: outgoing
|
|
strength: 0.8
|
|
edge_id: c7805bed-d50e-4016-b518-c0be2094d687
|
|
---
|
|
|
|
## Problem\nTwo modules mutually importing from each other (A imports from B, B imports from A) creates circular import errors.\n\n## Solution\nExtract the shared types/classes into a third dedicated `models.py`. Both A and B then import from `models.py`, breaking the cycle.\n\n## Applied In\npaper-dynasty/card-creation (feature/fullcard-migration branch):\n- `batters/calcs_batter.py` and `batters/card_builder.py` both needed `BattingCardRatingsModel`\n- Extracted it to `batters/models.py`\n- Same pattern applied for `pitchers/models.py`\n\n## Result\n- Eliminates lazy/function-body imports (which are an anti-pattern workaround)\n- Clean module-level imports throughout\n- No circular dependency
|