observing a behaviour on Python 3.7 b2 that doesn't match what's documented in PEP 538PEP 538 states that the locale coercion behaviour can be disabled through the PYTHONCOERCECLOCALE environment variable. I would then expect the stdin encoding to be the same as Python 3.6 when the C locale is specified with no encoding value. bash-3.2$ LANG=C python3.6 -c "import sys; print(sys.stdin.encoding)" US-ASCII bash-3.2$ LANG=C python3.7 -c "import sys; print(sys.stdin.encoding)" utf-8 bash-3.2$ PYTHONCOERCECLOCALE=0 LANG=C python3.7 -c "import sys; print(sys.stdin.encoding)" utf-8 LC_ALL is not set bash-3.2$ locale LANG="C" LC_COLLATE="C" LC_CTYPE="C" LC_MESSAGES="C" LC_MONETARY="C" LC_NUMERIC="C" LC_TIME="C" LC_ALL= Trying to dig into the reason why the env flag isn't disabling the behaviour I found some subsequent changes after the PEP which look to have broken the original implementation behaviour. https://github.com/python/cpython/commit/9454060e84a669dde63824d9e2fcaf295e34f687
> PYTHONCOERCECLOCALE=0 LANG=C python3.7 -c "import sys; print(sys.stdin.encoding)" Are you aware of the PEP 540 "UTF-8 Mode"? It's also enabled automatically by the POSIX locale. If you hate UTF-8, you have to use: PYTHONCOERCECLOCALE=0 python3.7 -X utf8=0 or PYTHONCOERCECLOCALE=0 PYTHONUTF8=0 python3.7
I cannot reproduce the issue with the future Python 3.7 beta4: vstinner@apu$ PYTHONCOERCECLOCALE=0 LANG=C ./python -X utf8=0 -c "import sys; print(sys.stdin.encoding)" ANSI_X3.4-1968 vstinner@apu$ LANG=C ./python -X utf8=0 -c "import sys; print(sys.stdin.encoding)" UTF-8 vstinner@apu$ ./python Python 3.7.0b3+ (heads/3.7:887b5f8fc6, May 2 2018, 09:54:18) [GCC 7.3.1 20180303 (Red Hat 7.3.1-5)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> The master branch works also as expected.