Message386203
| Author |
AndersMunch |
| Recipients |
AndersMunch, paul.moore, steve.dower, tim.golden, zach.ware |
| Date |
2021年02月03日.13:42:50 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1612359770.32.0.137300123748.issue43115@roundup.psfhosted.org> |
| In-reply-to |
| Content |
getlocale fails with an exception when the string returned by _setlocale is already an RFC 1766 language tag.
Example:
Python 3.10.0a4 (tags/v3.10.0a4:445f7f5, Jan 4 2021, 19:55:53) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, 'en-US')
'en-US'
>>> locale.getlocale()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\flonidan\env\Python310\lib\locale.py", line 593, in getlocale
return _parse_localename(localename)
File "C:\flonidan\env\Python310\lib\locale.py", line 501, in _parse_localename
raise ValueError('unknown locale: %s' % localename)
ValueError: unknown locale: en-US
Expected result:
('en-US', None)
See https://github.com/wxWidgets/Phoenix/issues/1637 for an example of the ensuing problems. wx.Locale calls C setlocale directly, but, as far as I can see, correctly, using dashes in the language code which is consistent with not only RFC 1766 but also the examples in Microsoft's documentation (https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/setlocale-wsetlocale?view=msvc-160). CPython seems to assume underscored names such as 'en_US' instead, as shown by getdefaultlocale inserting an underscore. |
|