-
-
Notifications
You must be signed in to change notification settings - Fork 32k
locale.resetlocale is broken #35920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
locale.resetlocale is broken #35920
Comments
locale.setlocale doesn't recognize the the format that The only way I've succeeded in setting the locale on |
Logged In: YES Mark, know anything about this? I don't. |
Logged In: YES Can you provide a detailed test case? AFAIK, no_NO is indeed |
Logged In: YES Sorry, I forgot to mention the testcase I am using. The To be more specific: And to clarify what input getdefaultlocale returns on my >>> locale.getdefaultlocale()
('no_NO', 'cp1252')
and:
>>> locale._build_localename(locale.getdefaultlocale())
'no_NO.cp1252' By the way, is this bug fixed in python 2.2? |
Logged In: YES Still reproducible with Python 2.4: Python 2.4b2 (#19, Nov 8 2004, 11:15:07)
[GCC 3.3.5 (Debian 1:3.3.5-2)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> import locale
>>> locale.getdefaultlocale()
['en_US', 'utf']
>>> locale.resetlocale()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/home/johannes/python/Lib/locale.py", line 389, in
resetlocale
_setlocale(category, _build_localename(getdefaultlocale()))
locale.Error: unsupported locale setting Note that if I run python with 'LANG=nl_NL python', the http://python.org/sf/813449 seems to be the same bug, BTW. |
Logged In: YES As this is not Windows specific, setting Category to Library. |
Logged In: YES I'm seeing this error on Fedora Core 4: Python 2.4.1 (#1, May 16 2005, 15:19:29)
[GCC 4.0.0 20050512 (Red Hat 4.0.0-5)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> import locale; locale.getdefaultlocale()
('en_US', 'utf')
>>> locale.resetlocale()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/locale.py", line 389, in resetlocale
_setlocale(category, _build_localename(getdefaultlocale()))
locale.Error: unsupported locale setting |
Logged In: YES The same applies to other locales. From bpo-813449 (a duplicate of this): If the intention is to compute the locale's encoding, |
Still a problems on py3k. Set stage to needs patch as it's so easy to reproduce. |
Can we simply document that getpreferredencoding should be used instead as stated in msg8781 ? Should getdefaultlocale be earmarked for deprecation? |
Adding support for locales that are not recognized is easy and the locale parser could also learn about formats that it doesn't yet understand, so patches are welcome. The main problem here is that setlocale() only understands a very limited set of locale names. Please note that locale.getdefaultlocale() is not the same as locale.getpreferredencoding():
|
It doesn't seem to me that we've really deprecated getdefaultlocale() -- it's not documented as such, and MAL makes the good point that getdefaultlocale() is trying to avoid calling setlocale(). Perhaps this is just a documentation problem? _build_localename() just glues together the language code and the encoding, resulting in things like en_US.ISO8859-1, which turns out to not work. So maybe we should document that getdefaultlocale() will sometimes guess wrong. |
Trying to come up with a short LC_MONETARY example for PEP-538, I just ran into what seems to be a related problem with locale.resetlocale(), which is that it doesn't 8000 work properly for categories other than LC_CTYPE: locale.getdefaultlocale() doesn't let you say which category you're actually interested in, so even if you specific a category for resetlocale(), it's going to look at the LC_CTYPE setting, *NOT* the one for the category you're interested in. So perhaps a suitable design change here would be to update resetlocale() to just pass an empty string (letting the underlying platform API call figure out the right default), rather than passing the result of locale.getdefaultlocale()? |
The issue is no longer reproducible (at least on Windows 10; can someone test it on Vista?): >>> import locale
>>> locale.getlocale(locale.LC_NUMERIC)
(None, None)
>>> locale.getdefaultlocale()
<stdin>:1: DeprecationWarning: Use setlocale(), getpreferredencoding(False) and getlocale() instead
('ru_RU', 'cp1251')
>>> locale.setlocale(locale.LC_ALL, 'no_NO')
'no_NO'
>>> locale.getlocale(locale.LC_ALL)
('no_NO', 'ISO8859-1')
>>> locale.getlocale(locale.LC_NUMERIC)
('no_NO', 'ISO8859-1') |
Windows 10, Norwegian Nynorsk locale, Python 3.11: H:\> py -3.11
Python 3.11.0b1 (main, May 7 2022, 22:58:47) [MSC v.1931 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getdefaultlocale()
<stdin>:1: DeprecationWarning: Use setlocale(), getencoding() and getlocale() instead
('nn_NO', 'cp1252')
>>> locale.resetlocale()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files\Python311\Lib\locale.py", line 636, in resetlocale
_setlocale(category, _build_localename(getdefaultlocale()))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
locale.Error: unsupported locale setting
>>> |
A |
You should use |
How can we modify the default value now? |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: