Add explicit encoding in open calls #249
Merged
+20
−19
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.
Having enabled
PYTHONWARNDEFAULTENCODING
on Python 3.10, I now get yelled at (which is a good thing!) whenever Python opens a file in text mode without an encoding specified, implicitly falling back on the locale. It just happened when callingjupyter server --generate-config
, so I took a bit of time to add explicit encoding arguments to open calls injupyter_core
.Please review if UTF-8 is the appropriate encoding in all cases, I'm not otherwise familiar with the codebase, so it's not always easy for me to see. Most of the calls seem to handle Python / CSS / JS files, where UTF-8 should be appropriate, but one of the functions I'm not entirely sure about is
paths.secure_write
, which can probably be used to write lots of different files (though that in turn means it can be used to write Python files, which should be UTF-8).