-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use system default encoding when passing code to PIPE #209
Labels
Comments
Thanks for supplying this information. I wasn't aware of the python code writing in a different encoding than the system default. This indeed needs to be solved, and I will have a look at it when I have time. |
+1 google/yapf#449 they already fixed! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On Windows system, if the source code contains non-ascii characters, the autopep8 and yapf will fail to format the code. For example,
Format above code with autopep8, it outputs
and yapf outputs,
This issue is related to #25, and only occurs on Windows. The reason is as follows.
Python 3 uses utf-8 as default encoding, and so does Linux system. The source code passing via PIPE will always be utf-8. But on Windows, it becomes tricky. With the following code, we can check the encoding used in Windows,
Windows system does not always use utf-8(65001) as its default encoding for console. In fact, it rarely use utf-8 as default setting. We can chagne the system setting to force windows to use utf-8, but I think it's beyond this topic.
On the other hand, vim-autoformat always encodes source code in utf-8 and pass it to PIPE, but the formatter program has no idea about the encoding and may assume it is the defualt encoding used by system.
I would like to recommend to get the encoding at run time, and uses it to encode the code. For example,
This should fix the issue we mentioned above and #25. Besides, it should not play negative effect for other system and encodings.
The text was updated successfully, but these errors were encountered: