diff --git a/graph/solutions/break-circular-imports-by-extracting-shared-models-to-models-b235f9.md b/graph/solutions/break-circular-imports-by-extracting-shared-models-to-models-b235f9.md new file mode 100644 index 00000000000..e8898ca8d8e --- /dev/null +++ b/graph/solutions/break-circular-imports-by-extracting-shared-models-to-models-b235f9.md @@ -0,0 +1,12 @@ +--- +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:18.326495+00:00" +--- + +## 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