Open m09 opened 5 years ago
There is an alternative: validate sys.getdefaultencoding()
at import time and if it is not utf-8
, print the workaround
(LC_ALL=UTF-8 python3 script.py
or export PYTHONIOENCODING=utf-8
) and exit immediately.
I like it more because:
encoding
for open
.encoding
and quite hard to maintain, unless there is a flake8 plugin.The majority of the third-party dependencies do not specify encoding for open.
bblfsh
, the main dependency we use to parse the files, enforces utf-8 for its input.
It is very easy to miss encoding and quite hard to maintain, unless there is a flake8 plugin. My proposal is much easier to implement.
Indeed I checked quickly and it seems there is no existing flake option. It makes for a great OSD though. I agree that the proposed fix is faster to implement but I also think it's worse: we can fix the problem directly and instead make using our tool harder to use in some cases.
ATM we often don't specify the encoding in
open
calls. We should instead specifyutf-8
everywhere because the default is platform dependent:That means all our
open
,pathlib.Path.read_text
and related calls should specifyencoding="utf-8"
.