Problem
The handle_import_from method in crates/cribo/src/code_generator/import_transformer.rs is over 570 lines long with deeply nested conditionals and duplicated logic. This violates the single responsibility principle and makes the code difficult to understand and maintain.
Proposed Solution
Break this method down into smaller, focused helper methods:
-
Extract namespace object creation logic (currently duplicated around lines 710-866 and 873-1022) into a dedicated helper method like create_namespace_object_assignments
-
Extract entry module duplicate check logic (lines 605-633) into a separate method
-
Extract submodule import handling logic (lines 641-1056) into a separate method
-
Extract wrapper module import handling (lines 1098-1137) into a separate method
Benefits
- Improved readability and maintainability
- Reduced code duplication
- Better adherence to single responsibility principle
- Easier testing of individual components
- Reduced cognitive complexity
References
Acceptance Criteria
Problem
The
handle_import_frommethod incrates/cribo/src/code_generator/import_transformer.rsis over 570 lines long with deeply nested conditionals and duplicated logic. This violates the single responsibility principle and makes the code difficult to understand and maintain.Proposed Solution
Break this method down into smaller, focused helper methods:
Extract namespace object creation logic (currently duplicated around lines 710-866 and 873-1022) into a dedicated helper method like
create_namespace_object_assignmentsExtract entry module duplicate check logic (lines 605-633) into a separate method
Extract submodule import handling logic (lines 641-1056) into a separate method
Extract wrapper module import handling (lines 1098-1137) into a separate method
Benefits
References
Acceptance Criteria
handle_import_frommethod is under 100 lines