Skip to content

Read packaged resources with UTF-8#3723

Closed
PEliet wants to merge 2 commits into
pre-commit:mainfrom
PEliet:fix/resource-text-encoding
Closed

Read packaged resources with UTF-8#3723
PEliet wants to merge 2 commits into
pre-commit:mainfrom
PEliet:fix/resource-text-encoding

Conversation

@PEliet

@PEliet PEliet commented Jul 20, 2026

Copy link
Copy Markdown

Summary

Read packaged text resources with an explicit UTF-8 encoding.

Background

pre_commit.util.resource_text() currently calls Traversable.read_text() without an encoding. That makes the result depend on the operating system's default text encoding. A packaged resource containing non-ASCII text can therefore fail to load or be decoded differently on systems using a non-UTF-8 locale.

Package resources are project-owned text files, so their encoding should be deterministic across local environments and CI.

Changes

  • Pass encoding='UTF-8' when reading packaged resources.
  • Add a regression test that verifies the explicit encoding and a non-ASCII result.

Tests

  • python -m pytest tests/util_test.py -q
  • git diff --check

All targeted tests passed locally.

@asottile asottile closed this Jul 20, 2026
@pre-commit pre-commit locked as spam and limited conversation to collaborators Jul 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants