Roundup Tracker - Issues

Message8247

Author rouilj
Recipients rouilj
Date 2025-01-01.19:23:57
Message-id <1735759437.96.0.413942107024.issue2551385@roundup.psfhosted.org>
In-reply-to
Issue1182919 (support range syntax for numbers), has a discussion of representing
a floating point number using "12345,24" where the comma is the decimal separator.

This localized representation doesn't seem to work as
hyperdb.py::Number.from_raw(self, value, *kw)
uses float() to convert value to a number. Float isn't locale aware.

  >>> string_number = "1234,56"
  >>> float(string_number)
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  ValueError: could not convert string to float: '1234,56'

Also it doesn't support ',' or '.' as thousand separators (but does support '_' for
thousand separators by python 3.8.

This conversion needs to use something like:

  >>> import locale
  >>> locale.setlocale(locale.LC_ALL, "en_DK.utf8")
  'en_DK.utf8'
  >>> string_number = "1.234,56"
  >>> float_number = locale.atof(string_number)
  >>> print(float_number)
  1234.56

which does support alternate thousand separators and decimal separators according
to the locale. (However thousand separators with exponent: locale.atof("1,234.56E3")
generates a ValueError in en_US but locale.atof("1.234,56E-2") generates (incorrectly)
1234.56 with en_HK (python 3.8.10).)

Currently the hyperdb is locale unaware. Also locale methods are not
thread safe (which might be an issue for roundup-server in thread mode). Some backends
like back_anydbm use float() directly for checks/conversions.

I am documenting the number input type in user_guide.txt as requiring a period
decimal separator, no thousands and supporting scientific notation.
History
Date User Action Args
2025-01-01 19:23:58rouiljsetrecipients: + rouilj
2025-01-01 19:23:57rouiljsetmessageid: <1735759437.96.0.413942107024.issue2551385@roundup.psfhosted.org>
2025-01-01 19:23:57rouiljlinkissue2551385 messages
2025-01-01 19:23:57rouiljcreate