STINNER Victor <vstin...@python.org> added the comment:
You should not use sys.getfilesystemencoding() nor locale.getpreferredencofing() to check if the C locale has been coerced, but read the LC_CTYPE locale instead: # C locale coerced $ LC_CTYPE=C python3 -c "import locale; print(locale.setlocale(locale.LC_CTYPE, ''))" C.UTF-8 # C locale not coerced: remains "C" $ LC_CTYPE=C PYTHONCOERCECLOCALE=0 python3 -c "import locale; print(locale.setlocale(locale.LC_CTYPE, ''))" C -- $ LC_CTYPE=C PYTHONCOERCECLOCALE=0 python3 -c "import sys; print(sys.getfilesystemencoding())" utf-8 In this example, the UTF-8 encoding is used because of the UTF-8 Mode: $ LC_CTYPE=C PYTHONCOERCECLOCALE=0 python3 -X utf8=1 -c "import sys; print(sys.getfilesystemencoding(), sys.flags.utf8_mode)" utf-8 1 $ LC_CTYPE=C PYTHONCOERCECLOCALE=0 python3 -X utf8=0 -c "import sys; print(sys.getfilesystemencoding(), sys.flags.utf8_mode)" ascii 0 The relationship between the PEP 538 and the PEP 540 is non obvious: https://www.python.org/dev/peps/pep-0540/#relationship-with-the-locale-coercion-pep-538 I guess that you would like: PYTHONUTF8=0 env var or -X utf8=0 command line option. -- I don't think that this issue is a bug, and so I suggest to close it as "not a bug". ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue38667> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com