diff --git a/graph/code-patterns/pattern-lazy-import-inside-function-body-to-break-circular-i-d637ad.md b/graph/code-patterns/pattern-lazy-import-inside-function-body-to-break-circular-i-d637ad.md index e51b73203de..2fbad947cb1 100644 --- a/graph/code-patterns/pattern-lazy-import-inside-function-body-to-break-circular-i-d637ad.md +++ b/graph/code-patterns/pattern-lazy-import-inside-function-body-to-break-circular-i-d637ad.md @@ -6,7 +6,13 @@ tags: [paper-dynasty, card-creation, card_builder, calcs_batter, circular_import importance: 0.6 confidence: 0.8 created: "2026-02-25T22:26:37.747893+00:00" -updated: "2026-02-25T22:26:37.747893+00:00" +updated: "2026-02-25T22:27:03.733654+00:00" +relations: + - target: c7623317-ea0a-4b8a-9375-65fc3aac5303 + type: FOLLOWS + direction: outgoing + strength: 0.8 + edge_id: 06095a46-699a-47bf-a1f1-418605b03d0f --- ## Problem\nbatters/card_builder.py imports from batters/calcs_batter.py (needs BattingCardRatingsModel). If calcs_batter.py also imported from card_builder.py at module level, this would cause a circular ImportError.\n\n## Solution: Lazy Import Inside Function Body\n```python\n# In batters/calcs_batter.py — inside get_batter_ratings():\ntry:\n from batters.card_builder import build_batter_full_cards\n vl_card, vr_card = build_batter_full_cards(...)\n vl_dict.update(vl_card.card_output())\n vr_dict.update(vr_card.card_output())\nexcept Exception as e:\n logger.warning(f'Card layout builder failed: {e}')\n```\n\nSame pattern used in pitchers/calcs_pitcher.py:\n```python\nfrom pitchers.card_builder import build_pitcher_full_cards\n```\n\n## Why It Works\nThe import only executes when the function is called, not at module load time, so the circular dependency never materializes at import resolution. diff --git a/graph/decisions/fullcard-migration-card-layoutpy-ported-to-card-creation-rep-c76233.md b/graph/decisions/fullcard-migration-card-layoutpy-ported-to-card-creation-rep-c76233.md index 3e6fa1ce8af..d10df629b19 100644 --- a/graph/decisions/fullcard-migration-card-layoutpy-ported-to-card-creation-rep-c76233.md +++ b/graph/decisions/fullcard-migration-card-layoutpy-ported-to-card-creation-rep-c76233.md @@ -6,13 +6,18 @@ tags: [paper-dynasty, card-creation, card_layout, fullcard, cardcolumn, migratio importance: 0.8 confidence: 0.8 created: "2026-02-25T22:26:22.293769+00:00" -updated: "2026-02-25T22:27:03.620028+00:00" +updated: "2026-02-25T22:27:03.733654+00:00" relations: - target: 52e4aa12-66ea-4c4b-9115-00099e4e4343 type: FOLLOWS direction: incoming strength: 0.8 edge_id: b663a957-e95e-49c1-b254-17567fc837f4 + - target: d637ad5b-0ad1-4164-b737-b870fce85ae1 + type: FOLLOWS + direction: incoming + strength: 0.8 + edge_id: 06095a46-699a-47bf-a1f1-418605b03d0f --- ## Context\nOn branch feature/fullcard-migration, created /mnt/NV2/Development/paper-dynasty/card-creation/card_layout.py.\n\n## What Was Ported\nPorted PlayResult, PLAY_RESULTS, EXACT_CHANCES, get_chances(), CardResult, CardColumn, FullCard, FullBattingCard, FullPitchingCard from database/app/card_creation.py.\n\n## Key Adaptations\n- card_output() uses col_* key names (col_one_2d6, col_one_results, col_one_d20, col_two_2d6, col_two_results, col_two_d20, col_three_2d6, col_three_results, col_three_d20) to match planned DB column names — NOT the database version's one_2d6, two_2d6 etc.\n- get_chances() always returns Decimal(str(val)) to avoid float/Decimal comparison TypeError\n- FullBattingCard and FullPitchingCard do NOT embed a ratings model (no ratings= param) to avoid circular imports; only offense_col and alt_direction are passed diff --git a/graph/edges/pattern-lazy-import-inside-fun--FOLLOWS--fullcard-migration-card-layout-06095a.md b/graph/edges/pattern-lazy-import-inside-fun--FOLLOWS--fullcard-migration-card-layout-06095a.md new file mode 100644 index 00000000000..bdeb2b7aeca --- /dev/null +++ b/graph/edges/pattern-lazy-import-inside-fun--FOLLOWS--fullcard-migration-card-layout-06095a.md @@ -0,0 +1,13 @@ +--- +id: 06095a46-699a-47bf-a1f1-418605b03d0f +type: FOLLOWS +from_id: d637ad5b-0ad1-4164-b737-b870fce85ae1 +from_title: "Pattern: Lazy import inside function body to break circular imports" +to_id: c7623317-ea0a-4b8a-9375-65fc3aac5303 +to_title: "FullCard Migration: card_layout.py ported to card-creation repo" +strength: 0.8 +created: "2026-02-25T22:27:03.733654+00:00" +updated: "2026-02-25T22:27:03.733654+00:00" +--- + +Lazy import pattern was needed to avoid circular imports introduced by the FullCard migration