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 <>
getlocale fails with an exception when the string returned by _setlocale is already an RFC 1766 language tag.


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')
>>> locale.getlocale()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\flonidan\env\Python310\lib\", line 593, in getlocale
    return _parse_localename(localename)
  File "C:\flonidan\env\Python310\lib\", line 501, in _parse_localename
    raise ValueError('unknown locale: %s' % localename)
ValueError: unknown locale: en-US

Expected result:
  ('en-US', None)

See 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 (  CPython seems to assume underscored names such as 'en_US' instead, as shown by getdefaultlocale inserting an underscore.
Date User Action Args
2021-02-03 13:42:50AndersMunchsetrecipients: + AndersMunch, paul.moore, tim.golden, zach.ware, steve.dower
2021-02-03 13:42:50AndersMunchsetmessageid: <>
2021-02-03 13:42:50AndersMunchlinkissue43115 messages
2021-02-03 13:42:50AndersMunchcreate