Closed gousaiyang closed 3 years ago
@gousaiyang Mind squashing the 2 commits into one and leaving the first commit's subject?
Specify encoding for
open()
Otherwise, I can do that for you. :blush:
I think you can click "Squash and merge"
@gousaiyang Yeah, some people may want to keep their names as "committers", not just "authors", so I always ask. :blush:
Thanks for your contribution! :smile:
This PR adds an
encoding
parameter to all calls to the builtinopen()
function in this project.Using
open()
without an explicit encoding is a common mistake (see PEP 597). The system default encoding is implicitly being used, making this library unusable on Windows (and possibly also on some Docker containers with locale not set) without patch.Since the
codes.json
file is totally controlled by us (and known to be UTF-8 encoded), just specify UTF-8 encoding foropen()
explicitly. Thefrom io import open
statement is for Python 2 compatibility (if still desired), since the builtinopen()
function in Python 2 does not allow specifying an encoding.This fixes #9, which has been there for a long time but no PRs have been created.