feat(file_read): add default encoding support #240
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.
Description
Add comprehensive text encoding support to the
file_read
tool.This allows proper handling of international text files (Japanese, Chinese, Korean, etc.) across all file reading modes.
encoding
parameter to all file reading functions withutf-8
defaultFILE_READ_ENCODING_DEFAULT
environment variable for global configurationExample issue:
In Japanese Windows environments, the default system encoding is CP932. When Python opens files without an explicit encoding specification, it uses this system default, which can cause UTF-8 text files to fail due to encoding errors.
This enhancement sets UTF-8 as the explicit default, preventing these common encoding failures.
Users can also override the encoding as needed via tool arguments or environment variables.
Note: This change may be slightly breaking for code that relies on the system default encoding.
Thank you!
Related Issues
Documentation PR
None (covered in docstrings).
Type of Change
Bug fixNew ToolBreaking changeDocumentation updateOther (please describe): Feature enhancement to existing tool
Testing
hatch fmt --formatter
hatch fmt --linter
hatch test
hatch run prepare
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.