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
sys.stdout.errors is set to "surrogateescape" #69526
Comments
The error handler of sys.stdout and sys.stdin is set to "surrogateescape" even for non-ASCII encoding. $ LANG= PYTHONIOENCODING=UTF-8 ./python -c 'import sys; print(sys.stdout.encoding, sys.stdout.errors)'
UTF-8 surrogateescape |
Sorry, I don't understand the issue. Do you consider that using surrogateescape is a bug? Which behaviour do you expect? Python 3.5 now uses surrogateescape by default for stdout and stderr when the locale is POSIX. I guess that you got the POSIX locale using "LANG=". |
I'm not sure this is a bug, but it looks at least unexpected, that surrogateescape is used with non-ASCII encoding. For example my last test for bpo-19058 fails on POSIX locale in 3.5+, and it is not so easy to make it working. May be change error handler to surrogateescape only if PYTHONIOENCODING is not specified? |
"it looks at least unexpected, that surrogateescape is used with non-ASCII encoding" What do you mean by non-ASCII encoding? surrogateescape is used by all encodings for all OS operations on Python 3, like os.listdir(), even for UTF-8. |
The default encoding of sys.stdio and sys.stdout is determined by (in order of increasing precedence):
The default error handler before 3.5 was determined by:
The default error handler since 3.5 (bpo-19977) is determined by:
Even if you explicitly specified the error handler by PYTHONIOENCODING, it doesn't have effect in POSIX locale. This doesn't look right to me. I think the order should be the same as for encoding. Proposed patch makes PYTHONIOENCODING to override locale default for error handler. |
What do you think about this Victor? |
I believe the problem may be that we can't readily tell the difference between "PYTHONIOENCODING=ascii" and "PYTHONIOENCODING=ascii:strict", and in the former case we'd ideally still end up using "surrogateescape" by default. That said, the real intent of the change was "If the detected encoding is ASCII, enable surrogateescape automatically", and detecting the POSIX locale was a proxy for that. We didn't account for PYTHONIOENCODING being used to select a more sensible encoding. |
Making "PYTHONIOENCODING=ascii" to mean "PYTHONIOENCODING=ascii:surrogateescape" is different (and may be more complex) issue. What error handler should use open(name, encoding='ascii')? open(name) in POSIX locale? This issue is about incorrect working of PYTHONIOENCODING in POSIX locale. |
Ok, I now understand the issue. Your change looks good to me. I agree that strict error handler is good choice for PYTHONIOENCODING=ascii. |
The patch looks good to me. |
New changeset 56eca1c08738 by Serhiy Storchaka in branch '3.5': New changeset 9c6623099da1 by Serhiy Storchaka in branch 'default': |
Thank you for your review Victor. I have added yet one minor change in tests because -I doesn't suppress PYTHONIOENCODING. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: