Merged
Conversation
This is mostly an issue on windows, but technically it affects
every OS. I know about this issue so there's no excuse, although I
guess this means there's no user on windows, or at least of the yaml
loader on windows.
The (well known, at least by me) problem where is that `open` in text
mode (the default) will retrieve the encoding it uses via
`locale.getencoding()` which is pretty much always the wrong thing to
do but it is what it is[^1].
On most unices this is innocuous because they generally have utf-8 set
as the locale encoding, but on windows it's generally going to fuck
you up because it likely has a stupid ANSI locale set (only if you're
really lucky has someone chanced setting 65001), leading to any
non-ascii content potentially breaking file reading as the codepage
will either not be able to decode it or will misread it.
Both JSON and PyYAML are perfectly happy reading binary files, in
which case they'll apply UTF-8 decoding and go on their merry
way, so change the code to that.
[^1]: it's finally being fixed in 3.15 by PEP 686
https://docs.python.org/3.15/whatsnew/3.15.html#whatsnew315-utf8-default
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is mostly an issue on windows, but technically it affects every OS. I know about this issue so there's no excuse, although I guess this means there's no user on windows, or at least of the yaml loader on windows.
The (well known, at least by me) problem where is that
openin text mode (the default) will retrieve the encoding it uses vialocale.getencoding()which is pretty much always the wrong thing to do but it is what it is1.On most unices this is innocuous because they generally have utf-8 set as the locale encoding, but on windows it's generally going to fuck you up because it likely has a stupid ANSI locale set (only if you're really lucky has someone chanced setting 65001), leading to any non-ascii content potentially breaking file reading as the codepage will either not be able to decode it or will misread it.
Both JSON and PyYAML are perfectly happy reading binary files, in which case they'll apply UTF-8 decoding and go on their merry way, so change the code to that.
Footnotes
it's finally being fixed in 3.15 by PEP 686 https://docs.python.org/3.15/whatsnew/3.15.html#whatsnew315-utf8-default ↩