bitmath icon indicating copy to clipboard operation
bitmath copied to clipboard

parse_string_unsafe() fails to parse strings with Bit or Byte unit

Open Mercury37 opened this issue 1 year ago • 1 comments
trafficstars

Expected behaviour

I was expecting parse_string_unsafe() to parse all of the following units, but at the very least the ones that parse_string() can parse:

  • b
  • bit
  • Bit
  • bits
  • Bits
  • B
  • byte
  • Byte
  • bytes
  • Bytes

Actual behaviour

parse_string_unsafe() fails for all strings consisting of a number and any of the above units:

parse_string_unsafe("1 b")

Results in an error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Python\Lib\site-packages\bitmath\__init__.py", line 1552, in parse_string_unsafe
    raise ValueError("The unit %s is not a valid bitmath unit" % unit)
ValueError: The unit B is not a valid bitmath unit

Similarly:

parse_string_unsafe("1 Byte")

Produces:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Python\Lib\site-packages\bitmath\__init__.py", line 1552, in parse_string_unsafe
    raise ValueError("The unit %s is not a valid bitmath unit" % unit)
ValueError: The unit ByteB is not a valid bitmath unit

The other units listed behave in the same way.

Versions

  • bitmath: 1.3.3.1 (PyPi)
  • Windows 10
  • Python 3.12.1

Mercury37 avatar Apr 29 '24 17:04 Mercury37

Hi there, I see your issue here and I will be looking at things here again soon. 2023 was especially busy for me and I am just now getting settled into a place where I can get back to work here. Thanks for your patience.

timlnx avatar Jun 02 '24 21:06 timlnx