-
Notifications
You must be signed in to change notification settings - Fork 19
Fix formatting files with unicode #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix formatting files with unicode #242
Conversation
|
Thank you for contributing! 👋 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes issue #168 by ensuring proper Unicode handling when reading and writing Python files during formatting and linting operations.
Key Changes:
- Added explicit UTF-8 encoding to all file read/write operations across the codebase
- Replaced
read_text()/write_text()withshutil.copyfile()in the diff generation path for better encoding preservation - Added a test fixture that forces ASCII encoding by default to catch any missing encoding specifications
- Added comprehensive test cases with Unicode characters (©, π, Gerät, デバイス, 장치, 设备, etc.) to verify the fix
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_cli/test_format.py | Added explicit UTF-8 encoding to test file reading to properly handle Unicode content |
| ni_python_styleguide/_utils/code_analysis.py | Added UTF-8 encoding to file reading in import region analysis |
| ni_python_styleguide/_fix.py | Added DEFAULT_ENCODING to multiple read/write operations and replaced read_text/write_text with shutil.copyfile for better encoding preservation |
| tests/conftest.py | Added autouse test fixture to force ASCII encoding by default, catching any missing encoding specifications |
| pyproject.toml | Removed unnecessary blank line for code cleanup |
| tests/test_cli/format_test_cases__snapshots/file_with_unicode/* | Added new test case files containing various Unicode characters to validate the fix |
| tests/test_cli/fix_test_cases__snapshots/unicode_example/* | Added test case files for Unicode handling in the fix command |
| tests/test_cli/acknowledge_existing_errors_test_cases__snapshots/unicode_in_files/* | Extended existing test case with additional Unicode data |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Adds a test for and fixes #168