Message355919
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". |
|
Date |
User |
Action |
Args |
2019-11-04 01:33:18 | vstinner | set | recipients:
+ vstinner, lazka |
2019-11-04 01:33:18 | vstinner | set | messageid: <1572831198.88.0.00174152530777.issue38667@roundup.psfhosted.org> |
2019-11-04 01:33:18 | vstinner | link | issue38667 messages |
2019-11-04 01:33:18 | vstinner | create | |
|