From 8d22bece6826c46ecdc6e7bb37f3d1ca6cbc7564 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Wed, 25 Feb 2026 16:44:41 -0600 Subject: [PATCH] relate: b235f924 --BUILDS_ON--> 9c7873fa --- ...s-also-move-its-module-level-helper-de-9c7873.md | 8 +++++++- ...LDS_ON--when-extracting-a-class-also-m-453428.md | 13 +++++++++++++ ...-by-extracting-shared-models-to-models-b235f9.md | 8 +++++++- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 graph/edges/break-circular-imports-by-extr--BUILDS_ON--when-extracting-a-class-also-m-453428.md diff --git a/graph/code-patterns/when-extracting-a-class-also-move-its-module-level-helper-de-9c7873.md b/graph/code-patterns/when-extracting-a-class-also-move-its-module-level-helper-de-9c7873.md index 0833003545a..f31df4c0229 100644 --- a/graph/code-patterns/when-extracting-a-class-also-move-its-module-level-helper-de-9c7873.md +++ b/graph/code-patterns/when-extracting-a-class-also-move-its-module-level-helper-de-9c7873.md @@ -6,7 +6,13 @@ tags: [python, refactoring, code-organization, circular-imports, paper-dynasty] importance: 0.7 confidence: 0.8 created: "2026-02-25T22:44:27.648627+00:00" -updated: "2026-02-25T22:44:27.648627+00:00" +updated: "2026-02-25T22:44:41.938081+00:00" +relations: + - target: b235f924-b532-40cd-be39-4fb765938add + type: BUILDS_ON + direction: incoming + strength: 0.8 + edge_id: 45342806-cdc6-478e-aa38-4294045aafe8 --- ## Pattern\nWhen extracting a class to a new file, check if any module-level helper functions are called from within the class's methods. Those helpers must move to the new file too — otherwise the new file would need to import back from the original file, re-creating a circular import.\n\n## Example (paper-dynasty/card-creation)\n`batters/models.py` received `BattingCardRatingsModel` plus 13 helper functions called by its methods:\n- `bp_singles`, `wh_singles`, `one_singles`\n- `bp_homeruns`, `triples`, `two_doubles`\n- `hit_by_pitch`, `strikeouts`\n- `flyout_a`, `flyout_bq`, `flyout_b`\n- `groundball_a`, `groundball_c`\n\nBy contrast, `pitchers/models.py` contains only `PitchingCardRatingsModel` because it had no module-level helper dependencies.\n\n## Rule\nBefore finalising a class extraction, grep the class body for any unqualified function calls and trace them back to their definition file. diff --git a/graph/edges/break-circular-imports-by-extr--BUILDS_ON--when-extracting-a-class-also-m-453428.md b/graph/edges/break-circular-imports-by-extr--BUILDS_ON--when-extracting-a-class-also-m-453428.md new file mode 100644 index 00000000000..3c629b968f0 --- /dev/null +++ b/graph/edges/break-circular-imports-by-extr--BUILDS_ON--when-extracting-a-class-also-m-453428.md @@ -0,0 +1,13 @@ +--- +id: 45342806-cdc6-478e-aa38-4294045aafe8 +type: BUILDS_ON +from_id: b235f924-b532-40cd-be39-4fb765938add +from_title: "Break circular imports by extracting shared models to models.py" +to_id: 9c7873fa-2c4e-4058-a315-cefb3c02788a +to_title: "When extracting a class, also move its module-level helper dependencies" +strength: 0.8 +created: "2026-02-25T22:44:41.938081+00:00" +updated: "2026-02-25T22:44:41.938081+00:00" +--- + +The helper-dependency pattern is a concrete rule that must be followed when applying the circular import extraction solution 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 index e8898ca8d8e..58177bccee2 100644 --- 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 @@ -6,7 +6,13 @@ 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" +updated: "2026-02-25T22:44:41.938081+00:00" +relations: + - target: 9c7873fa-2c4e-4058-a315-cefb3c02788a + type: BUILDS_ON + direction: outgoing + strength: 0.8 + edge_id: 45342806-cdc6-478e-aa38-4294045aafe8 --- ## 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