Skip to content

Modernize Python 2 compatibility code for Python 3.10+ - #230

Merged
dmort27 merged 1 commit into
masterfrom
modernize-python3
Oct 14, 2025
Merged

Modernize Python 2 compatibility code for Python 3.10+#230
dmort27 merged 1 commit into
masterfrom
modernize-python3

Conversation

@dmort27

@dmort27 dmort27 commented Oct 14, 2025

Copy link
Copy Markdown
Owner
  • 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:

  • Usage of deprecated pkg_resources package causing deprecation warnings
  • Unnecessary str() calls that were needed for Python 2 compatibility
  • Use of io.open() instead of built-in open() function
  • Redundant string casting in various places
  • What is the new behavior (if this is a feature change)?
    This PR modernizes the codebase for Python 3.10+ by:
  • Replacing pkg_resources with modern importlib.resources throughout the codebase
  • Enhancing the Rules class to handle both string paths and importlib.resources Path objects
  • Removing unnecessary str() calls that were needed for Python 2 compatibility
  • Replacing io.open() with built-in open() function
  • Removing redundant string casting in CSV readers and marisa_trie calls
  • Does this PR introduce a breaking change?
    No 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.resources
  • epitran/stripdiacritics.py - Replaced pkg_resources with importlib.resources
  • epitran/space.py - Replaced pkg_resources with importlib.resources
  • epitran/simple.py - Replaced pkg_resources, removed unnecessary str() calls
  • epitran/xsampa.py - Replaced pkg_resources with importlib.resources
  • epitran/puncnorm.py - Replaced pkg_resources with importlib.resources
  • epitran/reromanize.py - Replaced pkg_resources with importlib.resources
  • epitran/tir2pp.py - Replaced pkg_resources with importlib.resources
  • epitran/rules.py - Enhanced to handle importlib.resources Path objects, replaced io.open()
  • epitran/cedict.py - Removed redundant str() calls in marisa_trie usage
  • epitran/flite.py - Removed redundant str() calls in text processing

Key Improvements:

  • ✅ Eliminates all pkg_resources deprecation warnings
  • ✅ Modernizes resource loading using importlib.resources
  • ✅ Removes Python 2 compatibility overhead
  • ✅ Maintains full backward compatibility
  • ✅ All existing tests pass successfully

This modernization prepares the codebase for future Python versions and eliminates technical debt from Python 2 compatibility code.

- 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
dmort27 marked this pull request as ready for review October 14, 2025 21:12
@dmort27
dmort27 merged commit 2fca106 into master Oct 14, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants