[New-bugs-announce] [issue46659] Deprecate locale.getdefaultlocale() function

STINNER Victor report at bugs.python.org
Sun Feb 6 12:33:14 EST 2022


New submission from STINNER Victor <vstinner at python.org>:

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

----------
components: Library (Lib)
messages: 412647
nosy: vstinner
priority: normal
severity: normal
status: open
title: Deprecate locale.getdefaultlocale() function
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46659>
_______________________________________


More information about the New-bugs-announce mailing list