python-humanfriendly icon indicating copy to clipboard operation
python-humanfriendly copied to clipboard

parse_size does not distinguish between bits and bytes

Open Liam-Deacon opened this issue 5 years ago • 0 comments

humanfriendly (as of version 9.2) does not currently appear to differentiate between lower case 'b' to indicate bits and upper case 'B' to indicate bytes as per the abbreviation conventions.

For example I would expect the following comparisons to be False:

>>> humanfriendly.parse_size('10Gb') == humanfriendly.parse_size('10GB')
True

>>> humanfriendly.parse_size('10 gigabits') == humanfriendly.parse_size('10 gigabytes')
True

Furthermore, the following is just plain wrong:

>>> humanfriendly.parse_size('16 bits')  # should return the size in bytes as per docstring => 16 / 2**3 = 2 bytes
16

Is it possible to extend humanfriendly to recognise bit representations as well as bytes when supplying a size string?

Liam-Deacon avatar Jun 18 '21 09:06 Liam-Deacon