[issue13074] Improve documentation of locale encoding functions

New submission from Geoffrey Bache <gjb1002@users.sourceforge.net>: The locale module provides locale.getdefaultlocale and locale.getpreferredencoding. The encodings returned by each are generally subtly different ('ISO8859-1' vs 'ISO-8859-1'), but the difference between these methods is not explained. A comment by Martin von Löwis from 2003 in http://bugs.python.org/issue813449 indicates that "getdefaultlocale should not be used in new code", if this is really the case then this should be in the docs. Anyone reading the docs from the top will currently encounter getdefaultlocale first and believe that this is the way to get the encoding. ---------- assignee: docs@python components: Documentation messages: 144677 nosy: docs@python, gjb1002 priority: normal severity: normal status: open title: Improve documentation of locale encoding functions versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13074> _______________________________________

Changes by Ezio Melotti <ezio.melotti@gmail.com>: ---------- nosy: +ezio.melotti stage: -> needs patch versions: -Python 2.6, Python 3.1, Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13074> _______________________________________

Changes by Éric Araujo <merwok@netwok.org>: ---------- nosy: +eric.araujo, haypo, lemburg _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13074> _______________________________________

Mark Lawrence added the comment: Hopefully the patch speaks for itself. ---------- keywords: +patch nosy: +BreamoreBoy versions: +Python 3.4, Python 3.5 -Python 2.7, Python 3.2, Python 3.3 Added file: http://bugs.python.org/file35782/Issue13074.diff _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13074> _______________________________________

Marc-Andre Lemburg added the comment: The two functions serve a different purpose. getdefautltlocale() specifically avoids calling setlocale() and is thread-safe on Unix. It's purpose is to return the default locale string, not only the encoding. getpreferredencoding() only returns the encoding, but on Unix has to call setlocale() to return correct results and thus is not thread-safe. Martin's comment doesn't address this difference and I don't agree with it. Regarding the different results, I guess this could be solved by having both function pass the data obtained from the system through _parse_localname() before returning it, but that would have to be a handled in a new issue report. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13074> _______________________________________

Change by Mark Lawrence <breamoreboy@gmail.com>: ---------- nosy: -BreamoreBoy _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue13074> _______________________________________
participants (5)
-
Ezio Melotti
-
Geoffrey Bache
-
Marc-Andre Lemburg
-
Mark Lawrence
-
Éric Araujo