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 new file mode 100644 index 00000000000..0833003545a --- /dev/null +++ b/graph/code-patterns/when-extracting-a-class-also-move-its-module-level-helper-de-9c7873.md @@ -0,0 +1,12 @@ +--- +id: 9c7873fa-2c4e-4058-a315-cefb3c02788a +type: code_pattern +title: "When extracting a class, also move its module-level helper dependencies" +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" +--- + +## 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.