-
Notifications
You must be signed in to change notification settings - Fork 290
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
[fix] Reading utf8 encoded source code from windows stdin will throw UnicodeEncodeError #430
base: main
Are you sure you want to change the base?
Conversation
Thanks for contribution. Could you tell us more detailed information on the environment?
|
Windows-7-6.1.7601-SP1 64-bit |
I got this error yesterday when using vim ale to fix a utf-8 python script, and attempted to solve it, only to find that encoding is quite annoying. I have tried EmbolismSoil's solution but isn't perfect. Here is my test, the result is annoying but interersting.
And I'm using Windows 10 Version 1903 64-bit and Python 3.7.3 64-bit, cloned latest autopep8. |
The old version of the fix_code function uses stdin.encoding as the default input encoding, which is not the encoding of the input file. For example, you are editing a utf8 encoded file in vim on windows, and then output the contents of the vim buffer to autopep8 through the pipeline. At this time, since the stdin.encoding on windows(gb2312 as default) is different from the encoding of the buffered content of vim, UnicodeEncodeError exception will be thrown.
The fix for this problem is that stdin is only used as a byte input pipeline. autopep8 reads the source code that needs to be formatted by stdin as bytes, and then dynamically detects the encoding format.