You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
os.device_encoding() doesn't respect the UTF-8 Mode #86402
When the UTF-8 Mode is enabled, sys.stdout.encoding is always UTF-8, whereas os.devide_encoding(sys.stdout.fileno()) returns the locale encoding. os.devide_encoding() must return UTF-8 when the UTF-8 Mode is used.
I don't think UTF-8 mode should override os.device_encoding() on Windows.
UTF-8 mode can be used to ignore legacy locale encoding, and os.device_encoding() uses the locale encoding on Unix. So overriding it make sense.
But locale encoding and console cp are different on Windows. Users may want to know console cp even when they want to use UTF-8 by default for reading/writing text files.
But locale encoding and console cp are different on Windows. Users may want to know console cp even when they want to use UTF-8 by default for reading/writing text files.
You're right. My final change leaves Windows unchanged.
Activity
vstinner commentedon Nov 1, 2020
When the UTF-8 Mode is enabled, sys.stdout.encoding is always UTF-8, whereas os.devide_encoding(sys.stdout.fileno()) returns the locale encoding. os.devide_encoding() must return UTF-8 when the UTF-8 Mode is used.
vstinner commentedon Nov 1, 2020
In bpo-42208, I added C _Py_GetLocaleEncoding() function and Python _locale._get_locale_encoding() function.
vstinner commentedon Nov 1, 2020
New changeset 82458b6 by Victor Stinner in branch 'master':
bpo-42236: Enhance _locale._get_locale_encoding() (GH-23083)
82458b6
vstinner commentedon Nov 1, 2020
New changeset e662c39 by Victor Stinner in branch 'master':
bpo-42236: Use UTF-8 encoding if nl_langinfo(CODESET) fails (GH-23086)
e662c39
vstinner commentedon Nov 2, 2020
New changeset 4b9aad4 by Victor Stinner in branch 'master':
bpo-42236: Enhance init and encoding documentation (GH-23109)
4b9aad4
methane commentedon Nov 3, 2020
I don't think UTF-8 mode should override os.device_encoding() on Windows.
UTF-8 mode can be used to ignore legacy locale encoding, and os.device_encoding() uses the locale encoding on Unix. So overriding it make sense.
But locale encoding and console cp are different on Windows. Users may want to know console cp even when they want to use UTF-8 by default for reading/writing text files.
vstinner commentedon Nov 4, 2020
New changeset 3529718 by Victor Stinner in branch 'master':
bpo-42236: os.device_encoding() respects UTF-8 Mode (GH-23119)
3529718
vstinner commentedon Nov 4, 2020
You're right. My final change leaves Windows unchanged.