This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients vstinner
Date 2022-02-06.17:33:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1644168794.44.0.0658923518102.issue46659@roundup.psfhosted.org>
In-reply-to
Content
The locale.getdefaultlocale() function only relies on environment variables. At Python startup, Python calls setlocale() is set the LC_CTYPE locale to the user preferred encoding.

Since Python 3.7, if the LC_CTYPE locale is "C" or "POSIX", PEP 538 sets the LC_CTYPE locale to a UTF-8 variant if available, and PEP 540 ignores the locale and forces the usage of the UTF-8 encoding. The *effective* encoding used by Python is inconsistent with environment variables.

Moreover, if setlocale() is called to set the LC_CTYPE locale to a locale different than the user locale, again, environment variables are inconsistent with the effective locale.

In these cases, locale.getdefaultlocale() result is not the expected locale and it can lead to mojibake and other issues.

For these reasons, I propose to deprecate locale.getdefaultlocale(): setlocale(), getpreferredencoding() and getlocale() should be used instead.

For the background on these issues, see recent issue:

* bpo-43552
* bpo-43557
History
Date User Action Args
2022-02-06 17:33:14vstinnersetrecipients: + vstinner
2022-02-06 17:33:14vstinnersetmessageid: <1644168794.44.0.0658923518102.issue46659@roundup.psfhosted.org>
2022-02-06 17:33:14vstinnerlinkissue46659 messages
2022-02-06 17:33:14vstinnercreate