sphinx-contrib / emojicodes

An extension to use emoji codes in your Sphinx documentation! 😍
https://sphinxemojicodes.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
50 stars 15 forks source link

Specify encoding for `open()` #27

Closed gousaiyang closed 3 years ago

gousaiyang commented 3 years ago

This PR adds an encoding parameter to all calls to the builtin open() 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 for open() explicitly. The from io import open statement is for Python 2 compatibility (if still desired), since the builtin open() 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.

Peque commented 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:

gousaiyang commented 3 years ago

I think you can click "Squash and merge"

Peque commented 3 years ago

@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: