Modernize Python 2 compatibility code for Python 3.10+ - #230
Merged
Conversation
- Replace pkg_resources with importlib.resources throughout codebase - Update Rules class to handle both string paths and importlib.resources Path objects - Remove unnecessary str() calls that were needed for Python 2 compatibility - Replace io.open() with built-in open() function - Remove redundant str() casting in CSV reader parameters - Remove redundant str() casting in marisa_trie.RecordTrie calls - Remove redundant str() casting in text normalization functions This eliminates all Python 2 compatibility code and modernizes the codebase for Python 3.10+ while maintaining full backward compatibility. Co-authored-by: openhands <openhands@all-hands.dev>
dmort27
marked this pull request as ready for review
October 14, 2025 21:12
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 modernization and refactoring
What is the current behavior?
The codebase contains Python 2 compatibility code including:
pkg_resourcespackage causing deprecation warningsstr()calls that were needed for Python 2 compatibilityio.open()instead of built-inopen()functionThis PR modernizes the codebase for Python 3.10+ by:
pkg_resourceswith modernimportlib.resourcesthroughout the codebaseRulesclass to handle both string paths andimportlib.resourcesPath objectsstr()calls that were needed for Python 2 compatibilityio.open()with built-inopen()functionNo breaking changes. The modernization maintains full backward compatibility while eliminating deprecation warnings and improving code quality.
Changes Made
Files Modified:
epitran/ppprocessor.py- Replaced pkg_resources with importlib.resourcesepitran/stripdiacritics.py- Replaced pkg_resources with importlib.resourcesepitran/space.py- Replaced pkg_resources with importlib.resourcesepitran/simple.py- Replaced pkg_resources, removed unnecessary str() callsepitran/xsampa.py- Replaced pkg_resources with importlib.resourcesepitran/puncnorm.py- Replaced pkg_resources with importlib.resourcesepitran/reromanize.py- Replaced pkg_resources with importlib.resourcesepitran/tir2pp.py- Replaced pkg_resources with importlib.resourcesepitran/rules.py- Enhanced to handle importlib.resources Path objects, replaced io.open()epitran/cedict.py- Removed redundant str() calls in marisa_trie usageepitran/flite.py- Removed redundant str() calls in text processingKey Improvements:
pkg_resourcesdeprecation warningsimportlib.resourcesThis modernization prepares the codebase for future Python versions and eliminates technical debt from Python 2 compatibility code.