Skip to content

locale.nl_langinfo() can't decode THOUSEP monetary value #69998

Closed

Description

@serhiy-storchaka
BPO 25812
Nosy @malemburg, @loewis, @warsaw, @vstinner, @bitdancer, @serhiy-storchaka, @nnja

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:

assignee = 'https://github.com/nnja'
closed_at = None
created_at = <Date 2015-12-05.21:19:05.273>
labels = ['3.8', 'type-bug', 'library']
title = "locale.nl_langinfo() can't decode value"
updated_at = <Date 2019-01-09.11:53:37.581>
user = 'https://github.com/serhiy-storchaka'

bugs.python.org fields:

activity = <Date 2019-01-09.11:53:37.581>
actor = 'vstinner'
assignee = 'nnja'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2015-12-05.21:19:05.273>
creator = 'serhiy.storchaka'
dependencies = []
files = []
hgrepos = []
issue_num = 25812
keywords = []
message_count = 4.0
messages = ['255979', '267017', '267192', '333308']
nosy_count = 7.0
nosy_names = ['lemburg', 'loewis', 'barry', 'vstinner', 'r.david.murray', 'serhiy.storchaka', 'nnja']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue25812'
versions = ['Python 3.8']

Linked PRs

Activity

  1. serhiy-storchaka commented on Dec 5, 2015

    @serhiy-storchaka
    MemberAuthor
    >>> import locale
    >>> locale.setlocale(locale.LC_NUMERIC, 'uk_UA')
    'uk_UA'
    >>> locale.getlocale(locale.LC_NUMERIC)
    ('uk_UA', 'KOI8-U')
    >>> locale.nl_langinfo(locale.THOUSEP)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    UnicodeDecodeError: 'locale' codec can't decode byte 0x9a in position 0: Invalid or incomplete multibyte or wide character

    Looks as locale.nl_langinfo() always uses the UTF-8 encoding (or may be locale.getpreferredencoding()).

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    type-bugAn unexpected behavior, bug, or error
    on Dec 5, 2015
  3. nnja commented on Jun 3, 2016

    @nnja
    Contributor

    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')

  4. bitdancer commented on Jun 4, 2016

    @bitdancer
    Member

    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.

  5. vstinner commented on Jan 9, 2019

    @vstinner
    Member

    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".

  6. transferred this issue fromon Apr 10, 2022
  7. changed the title [-]locale.nl_langinfo() can't decode value[/-] [+]locale.nl_langinfo() can't decode THOUSEP monetary value[/+] on Sep 11, 2024
  8. added a commit that references this issue on Oct 4, 2024
  9. serhiy-storchaka commented on Oct 4, 2024

    @serhiy-storchaka
    MemberAuthor

    Thank you for suggestion @vstinner. #124963 applies the same solution to locale.nl_langinfo().

  10. added a commit that references this issue on Oct 8, 2024
  11. added
    3.14bugs and security fixes
    and removed on Oct 8, 2024
  12. serhiy-storchaka commented on Oct 8, 2024

    @serhiy-storchaka
    MemberAuthor

    The changes for localeconv() were not backported, so this one won't be either.

  13. added a commit that references this issue on Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions