Skip to content

Modernize Python 2 compatibility code to Python 3.10+ - #227

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

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

Conversation

@dmort27

@dmort27 dmort27 commented Oct 14, 2025

Copy link
Copy Markdown
Owner

Summary

This PR modernizes the codebase by removing Python 2 compatibility code and updating it to be compatible with Python 3.10 and above. Since Python 2 has reached end-of-life and is no longer supported, this modernization simplifies the codebase and takes advantage of Python 3's native Unicode support.

Changes Made

Setup and Dependencies

  • Updated setup.py to require Python 3.10+ with python_requires='>=3.10'
  • Removed Python 2-specific subprocess32 dependency
  • Updated Python version classifiers to reflect modern Python support

Code Modernization

  • Removed __future__ imports: Eliminated all from __future__ import statements (71 files affected)
  • Replaced unicodecsv: Updated all imports from unicodecsv to standard csv module
  • Fixed Unicode handling: Replaced unicode() function calls with str()
  • Updated CSV file handling: Changed from binary mode ('rb') to text mode ('r') with UTF-8 encoding
  • Fixed string literals: Removed unnecessary u'' Unicode string prefixes

Documentation Updates

  • Updated README.md examples to remove Python 2/3 version references
  • Added explicit Python 3.10+ requirement to installation instructions
  • Updated documentation links to point to Python 3 documentation
  • Fixed shebang line in reromanize.py from python2 to python3

Files Modified

  • Setup: setup.py
  • Core modules: 15+ Python files in epitran/ directory
  • Utilities: All files in epitran/bin/ directory
  • Tests: All test files updated for consistency
  • Documentation: README.md with modernized examples and requirements

Benefits

  1. Simplified codebase: Removed legacy compatibility code
  2. Better Unicode support: Leverages Python 3's native Unicode strings
  3. Modern dependencies: Uses standard library modules instead of compatibility packages
  4. Clearer requirements: Explicit Python version requirement prevents compatibility issues
  5. Future-ready: Prepared for modern Python development practices

Testing

The changes maintain backward compatibility for the public API while modernizing the internal implementation. All existing functionality should work identically, but now requires Python 3.10+.

Breaking Changes

  • Python version requirement: Now requires Python 3.10 or higher
  • Dependency changes: No longer depends on unicodecsv (uses standard csv module)

This is a significant modernization that brings the codebase up to current Python standards while maintaining all existing functionality.

- Updated setup.py to require Python 3.10+ and removed Python 2 dependencies
- Removed all __future__ imports from Python files
- Replaced unicodecsv imports with standard csv module
- Updated unicode() function calls to use str()
- Fixed CSV file handling to use proper text mode with UTF-8 encoding
- Updated documentation examples to remove Python 2/3 version references
- Fixed shebang line in reromanize.py from python2 to python3
- Updated documentation links to point to Python 3 docs

Co-authored-by: openhands <openhands@all-hands.dev>
@dmort27
dmort27 merged commit c2f948b 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