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.

classification
Title: locale.setlocale()
Type: Stage: resolved
Components: Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: setlocale error message is confusing
View: 3067
Assigned To: Nosy List: ned.deily, rene
Priority: normal Keywords:

Created on 2014-02-27 11:56 by rene, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg212350 - (view) Author: René Fleschenberg (rene) Date: 2014-02-27 11:56
locale.setlocale() does not work if you pass it a ``unicode`` object instead of a ``str`` (locale.py, line 576):

    ``if locale and type(locale) is not type(""):``

Maybe it would be better to do a check like this?

    ``if locale and not isinstance(locale, basestring):``

In particular, this can bite you if you use the ``unicode_literals`` future import, displaying a not-so-helpful error message ("ValueError: too many values to unpack" in _build_localename).
msg212382 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2014-02-27 20:27
Thanks for the report.  There was a lengthy discussion of this behavior a few years ago in Issue3067.  At that time it was decided not to change this behavior for 2.7.  I'm not sure if the __future__ "unicode_literals" was considered then, however you can work around it by using the b"" literal syntax:

    locale.setlocale(locale.LC_ALL, b'POSIX')
msg212459 - (view) Author: René Fleschenberg (rene) Date: 2014-02-28 16:59
I see. Thanks for the information.
History
Date User Action Args
2022-04-11 14:57:59adminsetgithub: 64992
2014-02-28 16:59:01renesetmessages: + msg212459
2014-02-27 20:27:36ned.deilysetstatus: open -> closed

superseder: setlocale error message is confusing

nosy: + ned.deily
messages: + msg212382
resolution: duplicate
stage: resolved
2014-02-27 11:56:07renecreate