Author vstinner
Recipients db3l, eryksun, guy.linton, jkloth, lukasz.langa, methane, ned.deily, paul.moore, serhiy.storchaka, steve.dower, terry.reedy, tim.golden, vstinner, xtreak, zach.ware
Date 2021-03-31.09:52:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
On Windows 10 build 1903,

vstinner@WIN C:\vstinner\python\master>python -m test test_locale -m test_getsetlocale_issue1813 -v
== CPython 3.10.0a6+ (heads/master:ff3c9739bd, Mar 31 2021, 12:43:26) [MSC v.1916 64 bit (AMD64)]
== Windows-10-10.0.18362-SP0 little-endian
ERROR: test_getsetlocale_issue1813 (test.test_locale.TestMiscellaneous)
Traceback (most recent call last):
  File "C:\vstinner\python\master\lib\test\", line 567, in test_getsetlocale_issue1813
    locale.setlocale(locale.LC_CTYPE, loc)
  File "C:\vstinner\python\master\lib\", line 610, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

It's a bug in the weird locale.getlocale() function which produces a locale name which doesn't exist:

vstinner@WIN C:\vstinner\python\master>python
>>> import locale
>>> locale.setlocale(locale.LC_CTYPE, "tr_TR") 
>>> locale.setlocale(locale.LC_CTYPE, None)
>>> locale.getlocale(locale.LC_CTYPE)           
('tr_TR', 'ISO8859-9')

>>> locale.setlocale(locale.LC_CTYPE, ('tr_TR', 'ISO8859-9'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\vstinner\python\master\lib\", line 610, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

>>> locale.setlocale(locale.LC_CTYPE, 'tr_TR')

If you use setlocale(LC_CTYPE, None) to get the locale, it works as expected.

IMO the getlocale() function is dangerous and should be removed: see bpo-43557 "Deprecate getdefaultlocale(), getlocale() and normalize() functions".
Date User Action Args
2021-03-31 09:52:47vstinnersetrecipients: + vstinner, terry.reedy, paul.moore, db3l, tim.golden, jkloth, ned.deily, methane, guy.linton, lukasz.langa, zach.ware, serhiy.storchaka, eryksun, steve.dower, xtreak
2021-03-31 09:52:47vstinnersetmessageid: <>
2021-03-31 09:52:47vstinnerlinkissue37945 messages
2021-03-31 09:52:46vstinnercreate