Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@Mercury37

Description

@Mercury37

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions