claude-memory/graph/solutions/break-circular-imports-by-extracting-shared-models-to-models-b235f9.md
2026-02-25 16:44:42 -06:00

1.3 KiB

id type title tags importance confidence created updated relations
b235f924-b532-40cd-be39-4fb765938add solution Break circular imports by extracting shared models to models.py
python
circular-imports
architecture
refactoring
paper-dynasty
0.8 0.8 2026-02-25T22:44:18.326495+00:00 2026-02-25T22:44:42.053812+00:00
target type direction strength edge_id
9c7873fa-2c4e-4058-a315-cefb3c02788a BUILDS_ON outgoing 0.8 45342806-cdc6-478e-aa38-4294045aafe8
target type direction strength edge_id
30d490e1-5ae8-4db8-a238-8973a09f99d1 BUILDS_ON outgoing 0.8 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