Skip to content

Use UTF-8 when sorting simple YAML files - #1288

Closed
davrens101 wants to merge 1 commit into
pre-commit:mainfrom
davrens101:fix/utf8-simple-yaml
Closed

davrens101 wants to merge 1 commit into
pre-commit:mainfrom
davrens101:fix/utf8-simple-yaml

Conversation

@davrens101

Copy link
Copy Markdown

I reproduced sort-simple-yaml crashing on Windows 10, Python 3.12 with PYTHONUTF8=0 and the native cp1252 locale. A UTF-8 YAML value containing Н raises UnicodeDecodeError when the hook opens the file using the locale encoding.

I made the hook explicitly read and write UTF-8 and documented that encoding. The regression covers both already-sorted and unsorted input, including preservation of the Unicode value after rewriting. Both cases fail without the change. All 14 sort-simple-yaml tests and Flake8 checks pass with it. A separate native Windows reproduction without monkeypatches now sorts the file successfully.

I used cross-platform locale probing. This contribution was generated with AI assistance; I am not claiming human code review.

@asottile asottile closed this Nov 13, 2026
@pre-commit pre-commit locked as spam and limited conversation to collaborators Nov 13, 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