You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
locale.nl_langinfo() can't decode THOUSEP monetary value #69998
Adding the test below to test__locale.py will reproduce the issue under the following conditions:
The locale uk_UA is installed on your system.
'uk_UA': (',', '\xa0') is added to the known_numerics dictionary in this test file
@unittest.skipUnless(nl_langinfo, "nl_langinfo is not available")
def test_lc_numeric_not_char_nl_langinfo(self):
# Test nl_langinfo against known values/
# It should still work if there's a mismatch between
# String & Numeric Locales
tested = False
for loc in candidate_locales:
try:
setlocale(LC_NUMERIC, loc)
except Error:
continue
for li, lc in ((RADIXCHAR, "decimal_point"),
(THOUSEP, "thousands_sep")):
if self.numeric_tester('nl_langinfo', nl_langinfo(li), lc, loc):
tested = True
if not tested:
self.skipTest('no suitable locales')
Thanks, Nina. We do have support in test.support for running a test with a specific locale (run_with_locale), so this could be turned into a unit test patch if you or someone else is willing to do that.
Since this bug has been reported, locale.localeconv() has been fixed in bpo-31900 to temporarily set LC_CTYPE to LC_NUMERIC to decode numeric fields of localeconv() from the proper encoding. I guess that a similar fix can be applied to locale.nl_langinfo(): set LC_CTYPE to LC_NUMERIC if the parameter is a numeric field.
I only knew locale.nl_langinfo(locale.CODESET). I didn't know that this function accepted other arguments :-)
I even wrote an article about these locale bugs :-) #5191
See also bpo-35697: "decimal: formatter error if LC_NUMERIC uses a different encoding than LC_CTYPE".
Activity
serhiy-storchaka commentedon Dec 5, 2015
Looks as locale.nl_langinfo() always uses the UTF-8 encoding (or may be locale.getpreferredencoding()).
nnja commentedon Jun 3, 2016
Adding the test below to test__locale.py will reproduce the issue under the following conditions:
The locale
uk_UAis installed on your system.'uk_UA': (',', '\xa0') is added to the
known_numericsdictionary in this test file@unittest.skipUnless(nl_langinfo, "nl_langinfo is not available")
def test_lc_numeric_not_char_nl_langinfo(self):
# Test nl_langinfo against known values/
# It should still work if there's a mismatch between
# String & Numeric Locales
tested = False
for loc in candidate_locales:
try:
setlocale(LC_NUMERIC, loc)
except Error:
continue
for li, lc in ((RADIXCHAR, "decimal_point"),
(THOUSEP, "thousands_sep")):
if self.numeric_tester('nl_langinfo', nl_langinfo(li), lc, loc):
tested = True
if not tested:
self.skipTest('no suitable locales')
bitdancer commentedon Jun 4, 2016
Thanks, Nina. We do have support in test.support for running a test with a specific locale (run_with_locale), so this could be turned into a unit test patch if you or someone else is willing to do that.
vstinner commentedon Jan 9, 2019
Since this bug has been reported, locale.localeconv() has been fixed in bpo-31900 to temporarily set LC_CTYPE to LC_NUMERIC to decode numeric fields of localeconv() from the proper encoding. I guess that a similar fix can be applied to locale.nl_langinfo(): set LC_CTYPE to LC_NUMERIC if the parameter is a numeric field.
I only knew locale.nl_langinfo(locale.CODESET). I didn't know that this function accepted other arguments :-)
I even wrote an article about these locale bugs :-)
#5191
See also bpo-35697: "decimal: formatter error if LC_NUMERIC uses a different encoding than LC_CTYPE".
[-]locale.nl_langinfo() can't decode value[/-][+]locale.nl_langinfo() can't decode THOUSEP monetary value[/+]pythongh-69998: Fix decoding error in locale.nl_langinfo()
serhiy-storchaka commentedon Oct 4, 2024
Thank you for suggestion @vstinner. #124963 applies the same solution to
locale.nl_langinfo().gh-69998: Fix decoding error in locale.nl_langinfo() (GH-124963)
serhiy-storchaka commentedon Oct 8, 2024
The changes for
localeconv()were not backported, so this one won't be either.pythongh-69998: Fix decoding error in locale.nl_langinfo() (pythonGH-…