New submission from STINNER Victor <vstin...@python.org>:

I propose to deprecate getdefaultlocale(), getlocale() and normalize() 
functions since they have multiple issues, and remove them in Python 3.12.


The normalize() function uses the locale.locale_alias dictionary which was 
copied from the X11 locale database in 2000. It's hard to keep this dictionary 
up to date and to support all locales of all platforms supported by Python. 
There are multiple issues on macOS for example.

getdefaultlocale() and getlocale() use heuristics to get an encoding from the 
locale name. These heuristics are not reliable.

getdefaultlocale() only rely on environment variables. When setlocale() is 
called, environment variables are not updated, and so the encoding returned by 
getdefaultlocale() is not the effective LC_CTYPE locale encoding. Example:
https://bugs.python.org/issue43552#msg389069

getlocale() open issues:

* bpo-20088: locale.getlocale() fails if locale name doesn't include encoding 
* bpo-23425: Windows getlocale unix-like with french, german, portuguese, 
spanish 
* bpo-33934: locale.getlocale() seems wrong when the locale is yet unset 
(python3 on linux) 
* bpo-38805: locale.getlocale() returns a non RFC1766 language code 
* bpo-43115: locale.getlocale fails if locale is set 

getdefaultlocale() open issue:

* bpo-6981: locale.getdefaultlocale() envvars default code and documentation 
mismatch 
* bpo-30755: locale.normalize() and getdefaultlocale() convert C.UTF-8 to 
en_US.UTF-8


Replacements:

* getdefaultlocale()[1] => getpreferredencoding(False) or 
get_current_locale_encoding(), see bpo-43552
* getlocale(loc) => setlocale(loc) or setlocale(loc, None)
* normalize => no replacement. There is no standard way to normalize a locale 
name.

----------
components: Library (Lib)
messages: 389086
nosy: vstinner
priority: normal
severity: normal
status: open
title: Deprecate getdefaultlocale(), getlocale() and normalize() functions
versions: Python 3.10

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43557>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to