Refactor __init__ methods to use **kwargs for cleaner parameter forwarding - #231
Merged
Conversation
…rding - Refactored Epitran.__init__ to use **kwargs instead of explicit parameter list - Updated SimpleEpitran.__init__ to extract parameters from **kwargs with defaults - Refactored all Epihan classes (Epihan, EpihanTraditional, EpiCanto, EpiJpan) to use **kwargs - Maintains full backward compatibility while eliminating parameter forwarding mess - Enables easier extension with new parameters without modifying multiple constructors - Improves code maintainability and follows Python best practices All existing functionality preserved. Constructor tests pass successfully. Co-authored-by: openhands <openhands@all-hands.dev>
dmort27
marked this pull request as ready for review
October 15, 2025 01:53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce? Code refactoring and improvement
What is the current behavior?
The
__init__methods throughout the codebase have messy parameter lists where parent constructors need to explicitly declare all parameters that any child class might need. For example:This creates a maintenance nightmare where adding a new parameter to any subclass requires updating all parent constructors in the chain.
This PR refactors the constructor chain to use
**kwargsfor cleaner parameter forwarding:Epitranclass: Now takes only the requiredcodeparameter explicitly, with all optional parameters passed via**kwargsSimpleEpitranclass: Extracts needed parameters from**kwargswith sensible defaultsEpihan,EpihanTraditional,EpiCanto,EpiJpan) now use**kwargspattern**kwargsparameters are clearly documented with their defaultsNo breaking changes. The refactoring maintains full backward compatibility:
Benefits
✅ Cleaner Code Architecture
✅ Improved Maintainability
✅ Better Documentation
Changes Made
Files Modified:
epitran/_epitran.py- Main Epitran class refactored to use **kwargsepitran/simple.py- SimpleEpitran class refactored to extract parameters from **kwargsepitran/epihan.py- All Chinese/Japanese classes refactored to use **kwargs patternTesting:
Example Usage
This refactoring eliminates the "messy
__init__functions" problem mentioned in the issue while maintaining complete backward compatibility and improving code quality.